Applet viewer window size setting
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. Calling ShowDialog raises the PrintPage event and renders the output to the PrintPreviewDialog control. You would typically call ShowDialog from the Click event-handling method of a button. PrintPreviewDialog1.Document = printDocument1Ĭall the ShowDialog method on the PrintPreviewDialog control. printPreviewDialog1.Document = printDocument1 Set the Document property of the PrintPreviewDialog control to the PrintDocument component on the form. ' If there are no more pages, reset the string to be printed. ' Check to see if more pages are to be printed.Į.HasMorePages = stringToPrint.Length > 0 StringToPrint = stringToPrint.Substring(charactersOnPage) ' Remove the portion of the string that has been printed. ' Draws the string within the bounds of the page.Į.Graphics.DrawString(stringToPrint, Me.Font, Brushes.Black, _Į.MarginBounds, StringFormat.GenericTypographic) StringFormat.GenericTypographic, charactersOnPage, linesPerPage) ' of stringToPrint that will fit within the bounds of the page.Į.Graphics.MeasureString(stringToPrint, Me.Font, e.MarginBounds.Size, _ ' Sets the value of charactersOnPage to the number of characters
Sub printDocument1_PrintPage(ByVal sender As Object, _īyVal e As PrintPageEventArgs) Handles printDocument1.PrintPage If there are no more pages, reset the string to be printed. Check to see if more pages are to be printed.Į.HasMorePages = (stringToPrint.Length > 0) Remove the portion of the string that has been printed. Draws the string within the bounds of the page.Į.Graphics.DrawString(stringToPrint, this.Font, Brushes.Black,Į.MarginBounds, StringFormat.GenericTypographic) of stringToPrint that will fit within the bounds of the page.Į.Graphics.MeasureString(stringToPrint, this.Font,Į.MarginBounds.Size, StringFormat.GenericTypographic,
Sets the value of charactersOnPage to the number of characters void printDocument1_PrintPage(object sender, PrintPageEventArgs e)
#Applet viewer window size setting code#
In the following code example, the event handler is used to print the "testPage.txt" file in the same font used on the form. You may have already completed steps 2 and 3 if you have implemented printing in your application. Also, make sure the PrintPage event is associated with its event-handling method. When the document has finished rendering, reset the string to be rendered. The PrintPage event is raised until HasMorePages is false. After each page is drawn, check to see if it is the last page, and set the HasMorePages property of the PrintPageEventArgs accordingly. Using (StreamReader reader = new StreamReader(stream))ĭim stream As New FileStream(docPath + docName, FileMode.Open)Īs you would for printing the document, in the PrintPage event handler, use the Graphics property of the PrintPageEventArgs class and the file contents to calculate lines per page and render the document's contents. Using (FileStream stream = new FileStream(docPath + docName, FileMode.Open)) Set the DocumentName property to the document you wish to print, and open and read the document's contents to the string you added previously. ' Declare a variable to hold the portion of the document that ' Declare a string to hold the entire document contents. Private WithEvents printDocument1 As New PrintDocument() Private printPreviewDialog1 As New PrintPreviewDialog() Declare a variable to hold the portion of the document that Declare a string to hold the entire document contents. Private PrintDocument printDocument1 = new PrintDocument() private PrintPreviewDialog printPreviewDialog1 = new PrintPreviewDialog() To preview a text document with a PrintPreviewDialog controlĪdd a PrintPreviewDialog, PrintDocument, and two strings to your form. An easy way to add print preview services to your application is to use a PrintPreviewDialog control in combination with the PrintPage event-handling logic for printing a file.
#Applet viewer window size setting windows#
It is very common in Windows Forms programming to offer print preview in addition to printing services.