简体   繁体   English

如何在 vb.net 申请表中打印 windows 中的特定区域

[英]How to print an specific area in windows application form in vb.net

I am new to vb.net so I don't know how to print.我是 vb.net 的新手,所以我不知道如何打印。 I am working on billing application in which a cashier enters details of customer and then selects items purchased and its price and quantity, these things then added in 'list view'.我正在开发计费应用程序,其中收银员输入客户的详细信息,然后选择购买的物品及其价格和数量,然后将这些东西添加到“列表视图”中。 After this i want that when user clicks a print button, it should print only specific area which i want to print.在此之后,我希望当用户单击打印按钮时,它应该只打印我想要打印的特定区域。 So, how to write a code for that.那么,如何为此编写代码。

If you want to print a specific area like a screenshot here is the code: Otherwise if want to print specific rows from your listview a give you other code:)如果您想打印特定区域(如屏幕截图),这里是代码:否则,如果要从列表视图中打印特定行,请给您其他代码:)

Dim WithEvents PrintDocument1 As Printing.PrintDocument = New Printing.PrintDocument


' Add a button on your Form "Button1" named and handle here the click event 
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    PrintDocument1.Print()
End Sub


' Printing process
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage



    Dim x As Single = 10 'e.MarginBounds.Left
    Dim y As Single = 10 'e.MarginBounds.Top

    'put here your width
    Dim mWidth As Integer = Me.Width

    'put here your height
    Dim mHeight As Integer = Me.Height

    ' Create you
    Dim bmp As New Bitmap(mWidth, mHeight)

    ' X cordinate
    Dim fromLeft As Integer = 0

    ' Y cordinate
    Dim fromTop As Integer = 0


    Me.DrawToBitmap(bmp, New Rectangle(fromLeft, fromTop, mWidth, mHeight))

    'Get the A4 size 
    Dim limitX As Integer = e.PageBounds.Width
    'use this to reduce your screenshot for the A4 format page
    Dim reduceMe As Double = limitX / mWidth


    Dim bmoToPrint As New Bitmap(bmp, CInt(mWidth * reduceMe), CInt(mHeight * reduceMe))

    e.Graphics.DrawImage(bmoToPrint, x, y, bmoToPrint.Width, bmoToPrint.Height)


End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM