我想打印我的表单(除了Button
控件之外的所有控件)。
但是我的表单中有一部分在我打印时不会出现。 如何让我的所有表格出现在纸上?
这是我的代码:
Try
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.GetType.FullName = "System.Windows.Forms.Button" Then
ctl.Visible = False
End If
Next
'Before printing, set Form.BackColor as White
Dim FormBackColor As Color = Me.BackColor
Me.BackColor = System.Drawing.Color.White
Me.Refresh()
'Printing the form
Dim PF As New Microsoft.VisualBasic.PowerPacks.Printing.PrintForm
PF.PrintAction = PrintAction.PrintToPreview
PF.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
'After printing, restore settings
For Each ctl In Me.Controls
If ctl.GetType.FullName = "System.Windows.Forms.Button" Then
ctl.Visible = True
End If
Next
Me.BackColor = FormBackColor
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try