what is the printing code?
- Hi
I made a notepad
I want to add a button to print
how can I do this?
may anyone help please...
Answers
Thank you Rudedog for your friendly help.
Hi Dan,
Welcome to MSDN forums!Here are some tutorials about printing feature in VB.NET:
1) Using PrintDocument, PrintDialog components to print form dataThe .NET Framework provides excellent support for Printing documents.
PrintDocument Component:
In the .NET Framework, a printed document is represented by the PrintDocument component. The PrintDocument object encapsulates all the information needed to print a page. They handle the events and operations of printing.
PrintDialog Component:
To print a document, we need to set the PrintDialog’s Document property to PrintDocument object, and use the PrintDocument object's Print method.
Private Sub buttonPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim printDialog1 As PrintDialog = New PrintDialog
printDialog1.Document = printDocument1
Dim result As DialogResult = printDialog1.ShowDialog
If (result = DialogResult.OK) Then
printDocument1.Print()
End If
End Sub
How Printing Works?
Printing content is provided directly by the application logic in the .NET Framework. You add a PrintDocument object and handle the PrintPage event which is called every time when a new page is to be printed. A print job is initiated by the PrintDocument's Print method. This starts the print job and raises one or more events. When the print job begins, a BeginPrint event occurs, followed by the PrintPage event for each page, followed by the EndPage event when the job is done. If the print job contains multiple pages, one PrintPage event will be raised for each page in the job making the PrintPage event to execute multiple times. The PrintPage event is the main event involved in printing documents. To send content to the printer, you must handle this PrintPage event and provide code to render the content in the PrintPage event handler.
Some tutorial:
Article: Printing feature in .NET Framework
http://www.startvbdotnet.com/controls/printdialog.aspx
Windows Forms Printing
http://www.syncfusion.com/faq/windowsforms/faq_c55c.aspx#q491q
How to print the content of RichTextBox using Visual Basic .NET?
http://support.microsoft.com/kb/811401
2) Using PrintForm component in Visual Basic Power Packs to print FormThe PrintForm component is designed to bring back the ability to easily print a Windows Form. With it, you can layout the Windows Form exactly as you want it and allow you to print the form as a quick report.
Microsoft Visual Basic Power Packs 3.0 Download
http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
End Sub
3) How to print external document using Process.Start method in VB.NET?
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
'psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "C:\MyFile.doc" ' Here specify a document to be printed
Process.Start(psi)
End Sub
End Class
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorThursday, November 12, 2009 7:48 AM
All Replies
Sorry, that I am not providing a working example that can drop right into your application bug free.
Printing Overview
Such a feat would be most notable indeed.
As of right now, I would deem it impossible.
Post some of your code if you need a more exact answer, something better than a general overview.
Rudedog =8^D
Your question made me chuckle.
It was a curiously simple question for someone with the skill to write an application similar to Notepad.
I built a working warp drive.
I want to add a button to start it up.
How can I do this?
Mark the best replies as answers. "Fooling computers since 1971."Thank you Rudedog for your friendly help.
Hi Dan,
Welcome to MSDN forums!Here are some tutorials about printing feature in VB.NET:
1) Using PrintDocument, PrintDialog components to print form dataThe .NET Framework provides excellent support for Printing documents.
PrintDocument Component:
In the .NET Framework, a printed document is represented by the PrintDocument component. The PrintDocument object encapsulates all the information needed to print a page. They handle the events and operations of printing.
PrintDialog Component:
To print a document, we need to set the PrintDialog’s Document property to PrintDocument object, and use the PrintDocument object's Print method.
Private Sub buttonPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim printDialog1 As PrintDialog = New PrintDialog
printDialog1.Document = printDocument1
Dim result As DialogResult = printDialog1.ShowDialog
If (result = DialogResult.OK) Then
printDocument1.Print()
End If
End Sub
How Printing Works?
Printing content is provided directly by the application logic in the .NET Framework. You add a PrintDocument object and handle the PrintPage event which is called every time when a new page is to be printed. A print job is initiated by the PrintDocument's Print method. This starts the print job and raises one or more events. When the print job begins, a BeginPrint event occurs, followed by the PrintPage event for each page, followed by the EndPage event when the job is done. If the print job contains multiple pages, one PrintPage event will be raised for each page in the job making the PrintPage event to execute multiple times. The PrintPage event is the main event involved in printing documents. To send content to the printer, you must handle this PrintPage event and provide code to render the content in the PrintPage event handler.
Some tutorial:
Article: Printing feature in .NET Framework
http://www.startvbdotnet.com/controls/printdialog.aspx
Windows Forms Printing
http://www.syncfusion.com/faq/windowsforms/faq_c55c.aspx#q491q
How to print the content of RichTextBox using Visual Basic .NET?
http://support.microsoft.com/kb/811401
2) Using PrintForm component in Visual Basic Power Packs to print FormThe PrintForm component is designed to bring back the ability to easily print a Windows Form. With it, you can layout the Windows Form exactly as you want it and allow you to print the form as a quick report.
Microsoft Visual Basic Power Packs 3.0 Download
http://msdn.microsoft.com/en-us/vbasic/bb735936.aspx
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.Scrollable)
End Sub
3) How to print external document using Process.Start method in VB.NET?
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim psi As New ProcessStartInfo
psi.UseShellExecute = True
psi.Verb = "print"
psi.WindowStyle = ProcessWindowStyle.Hidden
'psi.Arguments = PrintDialog1.PrinterSettings.PrinterName.ToString()
psi.FileName = "C:\MyFile.doc" ' Here specify a document to be printed
Process.Start(psi)
End Sub
End Class
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byMartin Xie - MSFTMSFT, ModeratorThursday, November 12, 2009 7:48 AM
- hi Martin
Thanls for your help
I tried the first but it Print a Blank page
Where do I have to put the text?
I didnt undrestand the others and Visual Basic 2010 give me errors when i try to use it
but thanks for your help
Sorry abou bad language if there :D - Hi Dan,
“I tried the first but it Print a Blank page
Where do I have to put the text?”
-> Besides PrintDocument.Print() action, you need to handle PrintDocument_PrintPage event to print text (Assuming that you used TextBox or RichTextBox to make your Notepad).
Please check this thread for code sample: How to use PrintDocument component to Print multiline and scrollable TextBox in VB.NET.
http://social.msdn.microsoft.com/Forums/en-US/vbpowerpacks/thread/2ad34554-e989-4ffa-8e1f-ccea1f00c99d
Best regards,
Martin Xie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


