vb.net Document_PrintPag 打印
我的打印思路是获得打印界面的范围,以图片形式传送到打印机打印1、PrivateSubCaptureScreen()'---获得需要打印的图片DimmygraphicsAs...
我的打印思路是 获得 打印界面的范围,以图片形式传送到打印机打印
1、Private Sub CaptureScreen() '---获得需要打印的图片
Dim mygraphics As Graphics = WebBrowser1.CreateGraphics()
Dim r As RECT
GetWindowRect(WebBrowser1.Handle, r)
Dim s As Rectangle
s = Rectangle.FromLTRB(r.Left, r.Top - 10, r.Right - 10, r.Bottom - 10)
memoryImage_1 = New Bitmap(s.Width, s.Height, mygraphics)
'Dim memoryGraphics As Graphics
memoryGraphics = Graphics.FromImage(memoryImage_1) ‘--就是这个memoryImage_1
Dim dc1 As IntPtr = GetWindowDC(WebBrowser1.Handle)
Dim dc2 As IntPtr = memoryGraphics.GetHdc()
BitBlt(dc2, 0, -20, s.Width - 10, s.Height, dc1, 0, 0, 13369376) '‘---------------测试
ReleaseDC(WebBrowser1.Handle, dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub
2、 Private Sub Document_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.DrawImage(memoryImage_1, print_x, print_y)
End Sub
3、 sub button1_click() '---执行打印
CaptureScreen() '--执行前面自定义函数截图
Dim pd As PrintDocument = New PrintDocument
pd.PrinterSettings = PrintDialog1.PrinterSettings
AddHandler pd.PrintPage, AddressOf Document_PrintPage
If _PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
pd.Print()
end sub
我现在的问题是,如何连续打印?比如我截了2次图
memoryImage_1,memoryImage_2
怎么才能点一次button1 就可以分别打印出 这两份图。(只打印一份时,格式我设置好了,一个图刚好满足一张打印纸) 展开
1、Private Sub CaptureScreen() '---获得需要打印的图片
Dim mygraphics As Graphics = WebBrowser1.CreateGraphics()
Dim r As RECT
GetWindowRect(WebBrowser1.Handle, r)
Dim s As Rectangle
s = Rectangle.FromLTRB(r.Left, r.Top - 10, r.Right - 10, r.Bottom - 10)
memoryImage_1 = New Bitmap(s.Width, s.Height, mygraphics)
'Dim memoryGraphics As Graphics
memoryGraphics = Graphics.FromImage(memoryImage_1) ‘--就是这个memoryImage_1
Dim dc1 As IntPtr = GetWindowDC(WebBrowser1.Handle)
Dim dc2 As IntPtr = memoryGraphics.GetHdc()
BitBlt(dc2, 0, -20, s.Width - 10, s.Height, dc1, 0, 0, 13369376) '‘---------------测试
ReleaseDC(WebBrowser1.Handle, dc1)
memoryGraphics.ReleaseHdc(dc2)
End Sub
2、 Private Sub Document_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)
e.Graphics.DrawImage(memoryImage_1, print_x, print_y)
End Sub
3、 sub button1_click() '---执行打印
CaptureScreen() '--执行前面自定义函数截图
Dim pd As PrintDocument = New PrintDocument
pd.PrinterSettings = PrintDialog1.PrinterSettings
AddHandler pd.PrintPage, AddressOf Document_PrintPage
If _PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
pd.Print()
end sub
我现在的问题是,如何连续打印?比如我截了2次图
memoryImage_1,memoryImage_2
怎么才能点一次button1 就可以分别打印出 这两份图。(只打印一份时,格式我设置好了,一个图刚好满足一张打印纸) 展开
展开全部
我帮你把最后一部分的语句顺序调换一下。你试一试
sub button1_click() '---执行打印
Dim pd As PrintDocument = New PrintDocument
pd.PrinterSettings = PrintDialog1.PrinterSettings
If _PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
for i=0 to 1 '这样可以两次截图
CaptureScreen() '--执行前面自定义函数截图
AddHandler pd.PrintPage, AddressOf Document_PrintPage
pd.Print()
Threading.Thread.sleep(100) ‘ 再加上一个间隔
next
end sub
sub button1_click() '---执行打印
Dim pd As PrintDocument = New PrintDocument
pd.PrinterSettings = PrintDialog1.PrinterSettings
If _PrintDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
for i=0 to 1 '这样可以两次截图
CaptureScreen() '--执行前面自定义函数截图
AddHandler pd.PrintPage, AddressOf Document_PrintPage
pd.Print()
Threading.Thread.sleep(100) ‘ 再加上一个间隔
next
end sub
追问
问题出在:我的webrowser是会显示两次不同的界面。运行后可以看到变化的。
变化前执行一次captureScreen,用picturebox显示图,变化后,再执行一次captureScreen,用picturebox显示图,然而得到的图却是一样的(都是第一张)。
发现问题应该出在截图这段代码的最后几行。无论怎么截图,他获得的都是第一次webbrowser的界面
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询