none
vb.net 中如何打印线条和文字 RRS feed

  • 问题

  • 我想做一个套印证书的小程序,将任意字符和线条打印到一张A4纸的某个位置上,请问需要使用那些控件和方法?

    myriceme

    2013年6月24日 2:57

答案

    • 已标记为答案 lilin 2013年6月24日 7:03
    2013年6月24日 3:17
  • 感谢Mark Shu,问题已解决。

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PrintDocument1.Print()
        End Sub
    
        Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            e.Graphics.DrawLine(New Pen(Color.Black, 0.5), 1, 1, 1, 200)
            DrawStringPointF(e)
        End Sub
    
        Public Sub DrawStringPointF(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            ' Create string to draw.
            Dim drawString As [String] = "Sample Text"
    
            ' Create font and brush.
            Dim drawFont As New Font("Arial", 16)
            Dim drawBrush As New SolidBrush(Color.Black)
    
            ' Create point for upper-left corner of drawing.
            Dim drawPoint As New PointF(250.0F, 250.0F)
    
            ' Draw string to screen.
            e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint)
        End Sub


    myriceme

    • 已标记为答案 lilin 2013年6月24日 7:03
    2013年6月24日 7:03

全部回复

    • 已标记为答案 lilin 2013年6月24日 7:03
    2013年6月24日 3:17
  • 感谢Mark Shu,问题已解决。

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PrintDocument1.Print()
        End Sub
    
        Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
            e.Graphics.DrawLine(New Pen(Color.Black, 0.5), 1, 1, 1, 200)
            DrawStringPointF(e)
        End Sub
    
        Public Sub DrawStringPointF(ByVal e As System.Drawing.Printing.PrintPageEventArgs)
            ' Create string to draw.
            Dim drawString As [String] = "Sample Text"
    
            ' Create font and brush.
            Dim drawFont As New Font("Arial", 16)
            Dim drawBrush As New SolidBrush(Color.Black)
    
            ' Create point for upper-left corner of drawing.
            Dim drawPoint As New PointF(250.0F, 250.0F)
    
            ' Draw string to screen.
            e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint)
        End Sub


    myriceme

    • 已标记为答案 lilin 2013年6月24日 7:03
    2013年6月24日 7:03