Ok. I try this but always gets error when click on printButton.
"Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.ToolBarButtonClickEventArgs'."
Sorry, I'm never try DirectCast or similar modification like this.
WithEvents printItem As ToolStripItem
Private preview As Boolean = False
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
printItem = DirectCast(DirectCast(PrintPreviewDialog1.Controls(1), ToolStrip).Items(0), ToolStripButton)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintPreviewDialog1.Document = PrintDocument1
PrintPreviewDialog1.ShowDialog() //there is error
End Sub
Private Sub printItem_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles printItem.MouseDown
preview = True
End Sub
Private Sub printItem_ButtonClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles printItem.Click
preview = False
'If e.Button Is tbt Then
If PrintDialog1.ShowDialog() = DialogResult.OK Then PrintDocument1.Print()
'End If
End Sub
Private Sub PrintDocument1_BeginPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
If preview = True Then e.Cancel = True
End Sub
Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.FillRectangle(Brushes.Black, 100, 100, 100, 100)
End Sub