我想在vb.net中打印一个winform(作为收据)。 [英] i want to print a winform (as receipt ) in vb.net.

查看:102
本文介绍了我想在vb.net中打印一个winform(作为收据)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个winform作为打印收据的设计。但现在我想打印这个tablelayoutpanel,以便用户可以打印。我必须使用VB.net Visual studio 2005.



i得到以下链接



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



但它在c#.net中,无法通过工具进行转换,因为它使用了一些互操作服务和dllimport。



请有人建议我采用正确的方法。



我从C#转换到vb.net后得到的代码



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

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

推荐答案

第一个两个解决方案提供了很好的信息。



您可能还想浏览我的文章以获取其他一些想法。



VB.NET中的Windows窗体截图和打印预览 [ ^ ]
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[^]


检查出来:如何使用VB.NET打印发票? [ ^ ]


请参阅我过去的答案,非常详细的一句:如何从C#中以其他形式打印窗体 [ ^ ]。



-SA
Please see my past answer, pretty detailed one: How can I print a windows form from another form in C#[^].

—SA


这篇关于我想在vb.net中打印一个winform(作为收据)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆