Print a Formm
-
Hi, Is it possible to print a Windows Form? I have a form that needs to be printed. I am not dealing with data source, but values objects. I am using VB .NET 2005. If a form cannot be printed, then what best approach is possible to give some results to print. Their is no Data Source. Just display values from objects, prepare a descent form and print it. Any help is highly appreciated. Thanks Trupti
Thanks Terry
-
Hi, Is it possible to print a Windows Form? I have a form that needs to be printed. I am not dealing with data source, but values objects. I am using VB .NET 2005. If a form cannot be printed, then what best approach is possible to give some results to print. Their is no Data Source. Just display values from objects, prepare a descent form and print it. Any help is highly appreciated. Thanks Trupti
Thanks Terry
Something like the Form Print Control[^] might be of use?
'--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd
-
Hi, Is it possible to print a Windows Form? I have a form that needs to be printed. I am not dealing with data source, but values objects. I am using VB .NET 2005. If a form cannot be printed, then what best approach is possible to give some results to print. Their is no Data Source. Just display values from objects, prepare a descent form and print it. Any help is highly appreciated. Thanks Trupti
Thanks Terry
Hello Trupti, Printing in Windows Forms consists primarily of using the PrintDocument Component (Windows Forms) component to enable the user to print, and the PrintPreviewDialog Control (Windows Forms) control, PrintDialog Component (Windows Forms) and PageSetupDialog Component (Windows Forms) components to provide a familiar graphical interface to users accustomed to the Windows operating system. Typically, you create a new instance of the PrintDocument component, set the properties that describe what to print using the PrinterSettings and PageSettings classes, and call the Print method to actually print the document. During the course of printing from a Windows-based application, the PrintDocument component will show an abort print dialog box to alert users to the fact that printing is occurring and to allow the print job to be canceled. The foundation of printing in Windows Forms is the PrintDocument component—more specifically, the PrintPage event. By writing code to handle the PrintPage event, you can specify what to print and how to print it. To create a print job: 1. Add a PrintDocument component to your form. 2. Write code to handle the PrintPage event. You will have to code your own printing logic. Additionally, you will have to specify the material to be printed. In the following code example, a sample graphic in the shape of a red rectangle is created in the PrintPage event handler to act as material to be printed. Visual Basic Copy Code Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.FillRectangle(Brushes.Red, New Rectangle(500, 500, 500, 500)) End Sub C# Copy Code private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.FillRectangle(Brushes.Red, new Rectangle(500, 500, 500, 500)); } J# Copy Code private void printDocument1_PrintPage(Object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.get_Graphics().FillRectangle(Brushes.get_Red(), new Rectangle(500, 500, 500, 500)); } C++ Copy Code private: void printDocument1_PrintPage(System::Object ^ sender, System::Drawing::Printing::PrintPageEventArgs ^ e) { e->Graphics->FillRectangle(Brushes::Red, Rectangle(500, 500, 500, 500)); } (Visual C#, Visual J# and Visual C++) Place the following code in the form's constructor to register the event handler. C