Hello everyone, I would like to enable my RTF editor to have the option of printing.

I looked on MSDN, but the code it represents is most confusing.

Can someone please have a look at the code they are showing, and break it down for me?

VB Code:
  1. ' Declare the PrintDocument object.
  2.     Private WithEvents docToPrint As New Printing.PrintDocument
  3.  
  4.     ' This method will set properties on the PrintDialog object and
  5.     ' then display the dialog.
  6.     Private Sub Button1_Click(ByVal sender As System.Object, _
  7.         ByVal e As System.EventArgs) Handles Button1.Click
  8.  
  9.         ' Allow the user to choose the page range he or she would
  10.         ' like to print.
  11.         PrintDialog1.AllowSomePages = True
  12.  
  13.         ' Show the help button.
  14.         PrintDialog1.ShowHelp = True
  15.  
  16.         ' Set the Document property to the PrintDocument for
  17.         ' which the PrintPage Event has been handled. To display the
  18.         ' dialog, either this property or the PrinterSettings property
  19.         ' must be set
  20.         PrintDialog1.Document = docToPrint
  21.  
  22.         Dim result As DialogResult = PrintDialog1.ShowDialog()
  23.  
  24.         ' If the result is OK then print the document.
  25.         If (result = DialogResult.OK) Then
  26.             docToPrint.Print()
  27.         End If
  28.  
  29.     End Sub
  30.  
  31.     ' The PrintDialog will print the document
  32.     ' by handling the document's PrintPage event.
  33.     Private Sub document_PrintPage(ByVal sender As Object, _
  34.        ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
  35.            Handles docToPrint.PrintPage
  36.  
  37.         ' Insert code to render the page here.
  38.         ' This code will be called when the control is drawn.
  39.  
  40.         ' The following code will render a simple
  41.         ' message on the printed document.
  42.         Dim text As String = "In document_PrintPage method."
  43.         Dim printFont As New System.Drawing.Font _
  44.             ("Arial", 35, System.Drawing.FontStyle.Regular)
  45.  
  46.         ' Draw the content.
  47.         e.Graphics.DrawString(text, printFont, _
  48.             System.Drawing.Brushes.Black, 10, 10)
  49.     End Sub