List Info

Thread: newbie programmer..printing help needed




newbie programmer..printing help needed
country flaguser name
United States
2008-03-06 21:43:27

Hi, newbie both to this board and to vb.net. i have no clue how to work with print code, still reading up but the subject looks very complicated (and scary). i'm using visual studio express 2008. i have a click-once windows application that functions as a calculator. goal is to allow users to print the actual windows form.vb application screen exactly as it appears to them with the calculated results on it, ideally to pdf, but i'll settle for paper! hoping anyone can either point me to simple (beginners) online resources or explain to me what parts of this sample code below i need to edit (and maybe provide an example of how). do i have to specify form controls in the code that renders the print job (ie, define the labels where the results appear to be printed)?? i have added a button and the printdialog component to my project and run with the sample code below (from msdn web), and it did print a page with the text in the example.. but i'm lost at the comment 'insert code to render page... how do you write the code that renders? is printdialog the right way to accomplish my goal? any guidance would be much appreciated, thanks.

sample code:

' Declare the PrintDocument object.
Private WithEvents docToPrint As New Printing.PrintDocument

' This method will set properties on the PrintDialog object and
' then display the dialog.
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click

' Allow the user to choose the page range he or she would
' like to print.
PrintDialog1.AllowSomePages = True

' Show the help button.
PrintDialog1.ShowHelp = True

' Set the Document property to the PrintDocument for
' which the PrintPage Event has been handled. To display the
' dialog, either this property or the PrinterSettings property
' must be set
PrintDialog1.Document = docToPrint

Dim result As DialogResult = PrintDialog1.ShowDialog()

' If the result is OK then print the document.
If (result = DialogResult.OK) Then
docToPrint.Print()
End If

End Sub

' The PrintDialog will print the document
' by handling the document's PrintPage event.
Private Sub document_PrintPage(ByVal sender As Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles docToPrint.PrintPage

' Insert code to render the page here.
' This code will be called when the control is drawn.

' The following code will render a simple
' message on the printed document.
Dim text As String = "In document_PrintPage method."
Dim printFont As New System.Drawing.Font _
("Arial", 35, System.Drawing.FontStyle.Regular)

' Draw the content.
e.Graphics.DrawString(text, printFont, _
System.Drawing.Brushes.Black, 10, 10)
End Sub

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )