How to print a multi-page text file in windows forms


















The filename will be displayed in the textbox. Step 2: In the Form1. Step 3: Now set some properties of the OpenFileDialog as shown below:. FilterIndex: 2. Title: Select a File to be printed. Step 4: Double click the Browse button. We will add code to select a text file and display the name of the file in the textbox. If openFileDialog1. OK Then. End If. End Sub. Step 5: Now declare a PrintDocument component in your form. Also declare a string that will be used to temporarily store the text to be printed.

Dim strPrint As String. Step 6: We will now create the Printing functionality. To do so, double click the Print button and add the following code.

The comments explain the code clearly:. DocumentName, FileMode. ReadToEnd ;. Print ;. AddHandler pd. End Using.

Step 7: The PrintPage event handler would look similar to the following:. MeasureString strPrint, this. Size, StringFormat. DrawString strPrint, this. GetObject "printPreImageDialog. Icon" ;. Skip to main content. Drawing; using System. Collections; using System. ComponentModel; using System. Forms; using System. Data; using System.

Printing; using System. Button btnLoad; private System. Button btnPrint; private System. Panel panImage; private Snowbnd simage; private string fileName; private int iLoaded; private int status; private System. PrintDocument printImage; private System. Button btnPreImage; private System. Also, make sure the PrintPage event is associated with its event-handling method. You may have already completed steps 2 and 3 if you have implemented printing in your application. In the following code example, the event handler is used to print the "testPage.

You would typically call ShowDialog from the Click event-handling method of a button. When the user clicks the print icon on the dialog, the PrintPage event is raised again, sending the output to the printer instead of the preview dialog. This is why the string is reset at the end of the rendering process in step 3. The following code example shows the Click event-handling method for a button on the form.

This event-handling method calls the methods to read the document and show the print preview dialog. Skip to main content.



0コメント

  • 1000 / 1000