【问题标题】:how to used print dialog box for print a document?如何使用打印对话框打印文档?
【发布时间】:2010-11-24 16:00:23
【问题描述】:

我正在开发一个项目,我必须在购买时打印账单。

我对所有账单都有一个特殊的页眉垫,这就是为什么,我该怎么做.... 一直......它保持...... 我有一张账单表格...... 我不知道怎么打印……

我如何获取数据并使用哪个对话框我可以执行(打印)它............

我用的是vs2010 ...... 我该怎么办…………

【问题讨论】:

  • 能否请您详细说明并显示一些关于您所拥有的代码。

标签: vb.net printing


【解决方案1】:
 PrintDialog printDialog1 = new PrintDialog()
 printDialog1.Document = printDocument1;
 DialogResult result = printDialog1.ShowDialog(this);
 if (result == DialogResult.OK)
 {
    printDocument1.Print();
 }

【讨论】:

    【解决方案2】:
    Public Class Form1
        Private WithEvents pd As Printing.PrintDocument
        ' storage for form image
        Dim formImage As Bitmap
        ' create API prototype
        Private Declare Function BitBlt Lib "gdi32.dll" Alias _
           "BitBlt" (ByVal hdcDest As IntPtr, _
           ByVal nXDest As Integer, ByVal nYDest As _
           Integer, ByVal nWidth As Integer, _
           ByVal nHeight As Integer, ByVal _
           hdcSrc As IntPtr, ByVal nXSrc As Integer, _
           ByVal nYSrc As Integer, _
           ByVal dwRop As System.Int32) As Long
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            pd = New Printing.PrintDocument
            Me.StartPosition = FormStartPosition.CenterScreen
    
        End Sub
        Private Sub pd_PrintPage(ByVal sender As Object, _
         ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
         Handles pd.PrintPage
            e.Graphics.DrawImage(formImage, 100, 100)
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            GetFormImage()
            pd.Print()
        End Sub
        Private Sub GetFormImage()
            Dim g As Graphics = Me.CreateGraphics()
            Dim s As Size = Me.Size
            formImage = New Bitmap(s.Width, s.Height, g)
            Dim mg As Graphics = Graphics.FromImage(formImage)
            Dim dc1 As IntPtr = g.GetHdc
            Dim dc2 As IntPtr = mg.GetHdc
            ' added code to compute and capture the form
            ' title bar and borders
            Dim widthDiff As Integer = _
               (Me.Width - Me.ClientRectangle.Width)
            Dim heightDiff As Integer = _
               (Me.Height - Me.ClientRectangle.Height)
            Dim borderSize As Integer = widthDiff \ 2
            Dim heightTitleBar As Integer = heightDiff - borderSize
            BitBlt(dc2, 0, 0, _
               Me.ClientRectangle.Width + widthDiff, _
               Me.ClientRectangle.Height + heightDiff, dc1, _
               0 - borderSize, 0 - heightTitleBar, 13369376)
    
            g.ReleaseHdc(dc1)
            mg.ReleaseHdc(dc2)
        End Sub
    
    End Class
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多