Printing gives unhandled exception. Access Denied
Posted
by Smoka
on Stack Overflow
See other posts from Stack Overflow
or by Smoka
Published on 2010-06-14T01:32:27Z
Indexed on
2010/06/14
1:42 UTC
Read the original article
Hit count: 347
Im newish to coding, currently on a Windows Forms App using CLI in VS10 Everything seems to work, my document shows fine in the Preview dialog but then crash's.
Heres only the code that seems relevant
private: System::Drawing::Printing::PrintDocument^ docPrint;
private: System::Windows::Forms::PrintDialog^ dlgPrint;
private: System::Windows::Forms::PrintPreviewDialog^ dlgPrintPreview;
this->button2 = (gcnew System::Windows::Forms::Button());
this->docPrint = (gcnew System::Drawing::Printing::PrintDocument());
this->dlgPrint = (gcnew System::Windows::Forms::PrintDialog());
this->dlgPrintPreview = (gcnew System::Windows::Forms::PrintPreviewDialog());
this->button2->Location = System::Drawing::Point(152, 355);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 53;
this->button2->Text = L"Print";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click_1);
//
// docPrint
//
this->docPrint->DocumentName = L"ResultsPage";
this->docPrint->PrintPage += gcnew System::Drawing::Printing::PrintPageEventHandler(this, &Form1::docPrint_PrintPage);
//
// dlgPrint
//
this->dlgPrint->Document = this->docPrint;
this->dlgPrint->UseEXDialog = true;
//
// dlgPrintPreview
//
this->dlgPrintPreview->AutoScrollMargin = System::Drawing::Size(0, 0);
this->dlgPrintPreview->AutoScrollMinSize = System::Drawing::Size(0, 0);
this->dlgPrintPreview->ClientSize = System::Drawing::Size(400, 300);
this->dlgPrintPreview->Document = this->docPrint;
this->dlgPrintPreview->Enabled = true;
this->dlgPrintPreview->Icon = (cli::safe_cast<System::Drawing::Icon^ >(resources->GetObject(L"dlgPrintPreview.Icon")));
this->dlgPrintPreview->Name = L"dlgPrintPreview";
this->dlgPrintPreview->Visible = false;
this->dlgPrintPreview->Load += gcnew System::EventHandler(this, &Form1::dlgPrintPreview_Load);
private: System::Void docPrint_PrintPage(System::Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ e) {
String ^ strDisplay = L"A Axis Rotations";
String ^ strDisplay2 = L"Centerline of Y" + CL_Y->Text + " + Z" + CL_Z->Text;
String ^ strDisplay3 = L"Initial Position Y" + G54_Y->Text + " + Z" + G54_Z->Text;
System::Drawing::Font ^ fntString = gcnew System::Drawing::Font(L"Times New Roman", 38, FontStyle::Bold);
e->Graphics->DrawString(strDisplay, fntString, Brushes::Black, 200,20);
e->Graphics->DrawString(strDisplay2, fntString, Brushes::Black, 80,150);
e->Graphics->DrawString(strDisplay3, fntString, Brushes::Black, 80,220);
e->Graphics->DrawString(Results->Text, fntString,Brushes::Black, 50,400);
}
private: System::Void button2_Click_1(System::Object^ sender, System::EventArgs^ e) {
// docPrint->Print;
dlgPrintPreview->ShowDialog();
}
private: System::Void dlgPrintPreview_Load(System::Object^ sender, System::EventArgs^ e) { }
Sorry if the formatting is ugly here.
© Stack Overflow or respective owner