Print a simple form

Schmidty

New member
Joined
Mar 6, 2006
Messages
3
Programming Experience
Beginner
I need to a print a complete form. It consits of combo boxs, labels, and textboxs. It will print but it is just blank. Thanks!

CODE:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintDocument1.Print()
End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
End Sub
 
Last edited:
Welcome, I moved thread to appropriate forum Reporting/Printing.

First, a simple solution if you just want to print the form as is displays on screen, have a look at this post containing a module I got from JuggaloBrotha and modified a bit: http://www.vbdotnetforums.com/showpost.php?p=25758&postcount=8

Secondly, in .Net printing you draw what you want and where you want and how you want, but you have to provide some code to do it - it won't just print if you do nothing. I see you have brought the PrintPage event handler (empty), here you use the e parameter and its Graphics instance. Use it like any other drawing, this is how you draw to the page. Here is the "hello printer" example
VB.NET:
'standard (sender, e) method parameters shortened
 
Private Sub PrintDocument1_PrintPage(sender, e) Handles PrintDocument1.PrintPage
  e.Graphics.DrawString("hello printed", [SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Font, Drawing.Brushes.Black, 10, 20)[/SIZE]
End Sub[SIZE=2]
[/SIZE]
 
Thanks for the response. I am still having problems. I am not sure what to put when it asks for "The Form as System.Windows.Forms.Form". The Form is Form1.

Thanks again!
------- Code -----------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

PrintForm(Form1, True, True, True)

End Sub

Public Sub PrintForm(ByVal TheForm As Form, _
Optional ByVal ButtonVisibility As Boolean = True, _
Optional ByVal centerX As Boolean = True, _
Optional ByVal centerY As Boolean = True)

'initialize
_centerX = centerX
_centerY = centerY
Pd = New System.Drawing.Printing.PrintDocument

Try
'Now, save active form as bmp to the
'clipboard by simulating <Alt> <Prt Sc> keystrokes
SendKeys.SendWait("%{PRTSC}")

'get clipboard bitmap
bmpForm = System.Windows.Forms.Clipboard.GetDataObject.GetData(System.Windows.Forms.DataFormats.Bitmap)

'print document
Pd.Print()
Catch err As Exception
MessageBox.Show(err.ToString(), "Print Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
 
I got it, Thanks for the code guys!!

I just put "Call PrintForm(Me)" that was in another post.

I am still learning and your code explained alot.

Regards,
Tony
 
Back
Top