我有一个打印功能,调用graphics.copyfromscreen方法进行屏幕截图,然后使用打印页面事件打印所述截图。一切都适用于所有控件,除了Checked列表框的内容没有显示在打印上任何有关让它们在打印时显示的帮助将不胜感激。
以下是.copyfromscreen方法的代码。
Private Sub CaptureScreen()
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)
For Each ctl As Control In Me.Controls
If TypeOf (ctl) Is Button Then
ctl.Visible = False
End If
Next ctl
Me.FormBorderStyle = FormBorderStyle.None
memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
Me.FormBorderStyle = FormBorderStyle.Sizable
For Each ctl As Control In Me.Controls
If TypeOf (ctl) Is Button Then
ctl.Visible = True
End If
Next ctl
End Sub
答案 0 :(得分:2)
不使用表格的文字截图,而是使用Control.DrawToBitmap()
method将其绘制到位图上。它应该显示CheckedListBox
的内容以及强制它被绘制到位图上,就好像它是一个常规形式一样。
'Hide all buttons.
For Each btn As Button In Me.Controls.OfType(Of Button)
btn.Visible = False
Next
'Dispose of the old bitmap to release memory.
If MemoryImage IsNot Nothing Then MemoryImage.Dispose()
MemoryImage = New Bitmap(Me.Width, Me.Height)
Me.DrawToBitmap(MemoryImage, New Rectangle(Point.Empty, Me.Size))
'Show all buttons.
For Each btn As Button In Me.Controls.OfType(Of Button)
btn.Visible = True
Next