Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i have a created a winform as design of print receipt . But now i want to print this tablelayoutpanel so that user can take a print . I have to user VB.net Visual studio 2005 .

i got this following link

http://www.c-sharpcorner.com/UploadFile/rahul4_saxena/print-receipt-and-save-data-using-window-form-in-C-Sharp/

but its in c#.net , not able to convert by tool because its using some interop service and dllimport .

Please anyone suggest me the right way to do it .

My code which i got after conversion from C# to vb.net

VB
Private Sub printDocument1_PrintPage(ByVal sender As System.Object, _
            e.Graphics.DrawImage(memoryImage, 0, 0);
       End Sub


       Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
           PrintScreen()
           PrintPreviewDialog1.ShowDialog()
       End Sub

      <System.Runtime.InteropServices.DllImport("gdi32.dll")> _
       Public static extern Long BitBlt(IntPtr hdcDest, Integer nXDest, Integer nYDest, Integer nWidth, Integer nHeight, IntPtr hdcSrc, Integer nXSrc, Integer nYSrc, Integer dwRop)
       Private memoryImage As Bitmap

       Private Sub PrintScreen()
           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)
           Dim dc1 As IntPtr = mygraphics.GetHdc()
           Dim dc2 As IntPtr = memoryGraphics.GetHdc()
           BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
           mygraphics.ReleaseHdc(dc1)
           memoryGraphics.ReleaseHdc(dc2)
       End Sub
Posted

The first two solutions give good information.

You may also want to browse my article for some other Ideas.

Windows Form Screenshot and Print Preview in VB.NET[^]
 
Share this answer
 
 
Share this answer
 
Please see my past answer, pretty detailed one: How can I print a windows form from another form in C#[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900