Advertisement
Guest User

Untitled

a guest
May 17th, 2013
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. // Declare the PrintDocument object.
  2. System::Drawing::Printing::PrintDocument^ docToPrint;
  3.  
  4. // This method will set properties on the PrintDialog object and
  5. // then display the dialog.
  6. void button6_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
  7. {
  8.    // Allow the user to choose the page range he or she would
  9.    // like to print.
  10.    printDialog1->AllowSomePages = true;
  11.  
  12.    // Show the help button.
  13.    printDialog1->ShowHelp = true;
  14.  
  15.    // Set the Document property to the PrintDocument for
  16.    // which the PrintPage Event has been handled. To display the
  17.    // dialog, either this property or the PrinterSettings property
  18.    // must be set
  19.    printDialog1->Document = docToPrint;
  20.  
  21.  
  22.    ;
  23.    ;
  24.    
  25.  
  26.    ;
  27.    ;
  28.    System::Windows::Forms::DialogResult result = printDialog1->ShowDialog();
  29.    System::Windows::Forms::MessageBox::Show( result.ToString() );
  30.    ;
  31.    ;
  32.  
  33.    // If the result is OK then print the document.
  34.    if ( result == System::Windows::Forms::DialogResult::OK )
  35.    {
  36.       docToPrint->Print();
  37.    }
  38.  
  39. }
  40.  
  41. // The PrintDialog will print the document
  42. // by handling the document's PrintPage event.
  43. void document_PrintPage( Object^ /*sender*/, System::Drawing::Printing::PrintPageEventArgs^ e )
  44. {
  45.    // Insert code to render the page here.
  46.    // This code will be called when the control is drawn.
  47.    // The following code will render a simple
  48.    // message on the printed document.
  49.    String^ text = textBox1->Text;
  50.    System::Drawing::Font^ printFont = gcnew System::Drawing::Font( "Arial",35,System::Drawing::FontStyle::Regular );
  51.  
  52.    // Draw the content.
  53.    e->Graphics->DrawString( text, printFont, System::Drawing::Brushes::Black, 10, 10 );
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement