winform 截圖 列印 會亂截(win10)

MStone Lin
請問

我要將winform 截圖後 再列印
在win7下都正常
可是在win10 就會亂截其他位置 而不是form的畫面
有將顯示比例調成100%
還是不行

請問那邊還需調整,或是有其他方式 可印winform的畫面嗎?

謝謝


Imports System.Drawing.Printing
Imports System.Collections.Generic
Imports System.Web
Imports BarcodeLib
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Net
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Net.Dns


Public Class Form5
    Inherits Form
    Private WithEvents printDocument1 As New PrintDocument
    Dim memoryImage As Bitmap


    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.CenterToScreen() '置中

        Dim x As Integer = 500
        Dim y As Integer = 400
        Me.Location = New Point(x, y)

        Me.Show()

    End Sub


 Private Sub Form5_show(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Shell("cmd.exe /c %windir%\explorer.exe shell:::{3080F90D-D7AD-11D9-BD98-0000947B0257}", AppWinStyle.MinimizedNoFocus)

        TopMost = True

        Dim s() As String
        s = Environment.GetCommandLineArgs

         Label5.Text = s.ToString

        If s.Length > 1 Then

            Label5.Text = s(1)

            Dim barcode As String = Label5.Text

               Dim bc As Barcode = New Barcode

                bc.Width = 175
                bc.Height = 32

                '  PictureBox1.Size = New Size(157, 20)

                PictureBox1.Image = bc.Encode(TYPE.CODE128, Label5.Text, bc.Width, bc.Height)

                printDocument1.PrinterSettings.PrinterName = "BarCodePrinter" ' 設定應用程式輸出印表機

                System.Threading.Thread.Sleep(2000)

                CaptureScreen()

                printDocument1.Print()

                ' 我先將畫面存檔, 若 OK 再改回 printDocument1.Print()
                'memoryImage.Save("D:\ttt.bmp")
         

            End If

            con1.Close()
            con1.Dispose()

        End If

        '  Application.Exit()

    End Sub

  Private Sub CaptureScreen()
        ' printButton.Visible = False
        ' clo.Visible = False
        Dim myGraphics As Graphics = Me.CreateGraphics()
        Dim s As Size = Me.Size
        memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
        Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
        Application.DoEvents()
        memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
    End Sub

    Private Sub printDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printDocument1.PrintPage
        e.Graphics.DrawImage(memoryImage, 0, 0)
    End Sub

    'Public Shared Sub Main()
    '    Application.Run(New Form1())
    'End Sub


End Class


回到頂部