none
关于VB form 打印有参考例子么? form 可以直接输出成pdf 或者 图片 打印么? RRS feed

答案

  • 没有啊,有保存在桌面啊。

    你有试过我的代码?代码会弹出窗体让你保存在哪个位置的。



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2018年9月27日 8:51

全部回复

  • Hi,

    你是想直接打印窗体?

    Imports System.Drawing.Printing
    
    Public Class Form1
        Dim memoryImage As Bitmap = Nothing
        Dim printDocument As PrintDocument = New PrintDocument()
    
        Private Sub CaptureScreen()
            Dim form As Form = Me
    
            Dim mygraphics As Graphics = form.CreateGraphics()
                memoryImage = New Bitmap(form.Width, form.Height, mygraphics)
                Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
                memoryGraphics.CopyFromScreen(form.Location.X, form.Location.Y, 0, 0, form.Size)
    
        End Sub
    
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            CaptureScreen()
            printDocument1.Print()
        End Sub
    
        Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
            e.Graphics.DrawImage(memoryImage, 0, 0)
        End Sub
    End Class
    

    Best Regards,

    Alex



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月26日 9:22
  • printDocument1.Print() ????
    2018年9月26日 9:40
  • Hi,

    加一个控件

    不加也行,但是需要更多的代码,如果你需要我可以写给你

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月26日 9:44
  • 谢谢。

    目前我遇到的问题是:能否通过 某种方法  转换pd  或者eg 成图片打印出来 ?

    因为不同打印机打印的效果不一样  默认设置A4大小

       Dim pd As New System.Drawing.Printing.PrintDocument
       pd.DefaultPageSettings.Landscape = True
       AddHandler pd.PrintPage, AddressOf pd_PrintPage
       pd.Print() 

        Public Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            Dim eg As Graphics
            eg = e.Graphics
            gPrint.FormControls(eg, frmPrint)    '主要是通过 eg.DrawString  画图 画线

        End Sub


    2018年9月26日 12:00
  • 因为不同打印机打印的效果不一样  默认设置A4大小

       Dim pd As New System.Drawing.Printing.PrintDocument
       pd.DefaultPageSettings.Landscape = True
       AddHandler pd.PrintPage, AddressOf pd_PrintPage
       pd.Print() '直接打印  不同打印机效果不一样比较头疼

        Public Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            Dim eg As Graphics
            eg = e.Graphics
            gPrint.FormControls(eg, frmPrint)    '主要是通过 eg.DrawString  画图 画线

        End Sub

    • 已合并 Alex-KSGZ 2018年9月27日 8:58 same case
    2018年9月27日 2:19
  • Hi,

    你的意思是,你不想要打印出来是pdf格式,想要图片格式?

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月27日 6:02
  • 你这种是直接打印 ,能先保存成PDF 或者 保存成 图片再打印么?  复杂的代码 我能看看么?
    2018年9月27日 7:22
  • 没有啊,有保存在桌面啊。

    你有试过我的代码?代码会弹出窗体让你保存在哪个位置的。



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2018年9月27日 8:51