Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have this code in c++ windows form application... but it print blank page... how to fix this?
what im doing wrong?

C++
#pragma endregion
		// Declare the PrintDocument object.

	private: System::Void Button1_Click_1(System::Object^  sender, System::EventArgs^  e) {
   PrintDialog1->AllowSomePages = true;

   PrintDialog1->ShowHelp = true;

   PrintDocument ^docToPrint = gcnew PrintDocument;
   PrintDialog1->Document = docToPrint;
   if ( docToPrint == nullptr )
         System::Windows::Forms::MessageBox::Show(  "null" );

   
   
   if ( PrintDialog1 == nullptr )
         System::Windows::Forms::MessageBox::Show(  "pnull" );

   
   
   System::Windows::Forms::DialogResult result = PrintDialog1->ShowDialog();
   System::Windows::Forms::MessageBox::Show( result.ToString() );
   
   

   if ( result == System::Windows::Forms::DialogResult::OK )
   {
	   docToPrint->Print();
   }

			 }
private: System::Void document_PrintPage_1(System::Object^  sender, System::Drawing::Printing::PrintPageEventArgs^  e) {
   String^ text = "In document_PrintPage method.";
   System::Drawing::Font^ printFont = gcnew System::Drawing::Font( "Times New Roman",20,System::Drawing::FontStyle::Bold );

   e->Graphics->DrawString("EAK TEAM TEST!!!",printFont,Brushes::Black,50,50);
   e->Graphics->DrawString( text, printFont, System::Drawing::Brushes::Black, 10, 10 );
		 }
Posted
Comments
Sergey Alexandrovich Kryukov 16-Apr-13 14:40pm    
Did you try to debug it? Place a break point at DrawString, see what happens...
—SA
[no name] 16-Apr-13 14:52pm    
i try... but nothing
Sergey Alexandrovich Kryukov 16-Apr-13 14:55pm    
"but nothing" is not informative. If you need help, you have to collaborate...
—SA
[no name] 16-Apr-13 14:47pm    
You need to actually read the text for the sample code you copy from, "This example requires that the button's Click event and the PrintPage event of docToPrint have been connected to the event-handling methods defined in this example." Did you wire the document print page event up?
[no name] 16-Apr-13 14:55pm    
Button1 even : this->Button1->Click += gcnew System::EventHandler(this,&Form1::Button1_Click_1);
printpage event : this->document->PrintPage += gcnew System::Drawing::Printing::PrintPageEventHandler(this, &Form1::document_PrintPage_1);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900