none
Printing question about margins & page setup not setting correctly

    Question

  • I'm sure I'm not doing this right, but I can't seem to get it. I have the code below which is for a page setup, print preview, and print button. When I set up the margins in the page setup, shouldn't the stuff on the page shift depending on what I set the margins to? Here is the code:

    private: System::Void printPreviewToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
    		{
    			docPrint->DefaultPageSettings = this->PageSetupDialog1->PageSettings;
    			docPrint->PrinterSettings = this->PageSetupDialog1->PrinterSettings;
    			this->printPreviewDialog1->ShowDialog();
    		}
    
    private: System::Void printToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
    		{
    			if (dlgPrint->ShowDialog() == System::Windows::Forms::DialogResult::OK)
    			  docPrint->Print();
    		}	
    
    private: System::Void docPrint_PrintPage(System::Object^ sender, System::Drawing::Printing::PrintPageEventArgs^ e) 
    		{
    			e->Graphics->DrawLine(gcnew Pen(Color::Black, 2), 60, 90, 720, 90);
    			e->Graphics->DrawLine(gcnew Pen(Color::Black, 1), 60, 93, 720, 93);
    			
    			String ^ strDisplay = L"Board Information";
    			System::Drawing::Font ^ fntString = gcnew System::Drawing::Font(L"Times New Roman", 16, FontStyle::Bold);
    			e->Graphics->DrawString(strDisplay, fntString, Brushes::Black, 80, 100);
    		}
    private: System::Void pageSetupToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
    		{
    			this->PageSetupDialog1->PageSettings = gcnew System::Drawing::Printing::PageSettings;
    
    			this->PageSetupDialog1->PrinterSettings = gcnew System::Drawing::Printing::PrinterSettings;
    
    			this->PageSetupDialog1->ShowNetwork = false;
    
    			System::Windows::Forms::DialogResult result = PageSetupDialog1->ShowDialog();
    
    			docPrint->DefaultPageSettings = this->PageSetupDialog1->PageSettings;
    			docPrint->PrinterSettings = this->PageSetupDialog1->PrinterSettings;
    		}
    

    Right now, I just have it printing a title with a few lines for testing. The title is located at 80, 100, but I'm guessing I am calling that out wrong if I want it to shift with the margins correct?

    I also can't seem to save the page setup options. everytime I open the page setup, it's back at the default, but I thought it was supposed to save the current as the default?

    Thanks for any help.

     


    Joining the <Dark Side>
    Tuesday, November 09, 2010 4:48 PM

Answers

  • If  you want  the origin at the margins, you have to explicitly set the OriginAtMargins property to true. 

    The PrintDocument carries the Printer and Page settings.  Set the Document property of your dialogs to your PrintDocument.

     

    • Marked as answer by Jing0Moderator Saturday, November 20, 2010 5:13 PM
    Tuesday, November 09, 2010 7:38 PM

All replies

  • If  you want  the origin at the margins, you have to explicitly set the OriginAtMargins property to true. 

    The PrintDocument carries the Printer and Page settings.  Set the Document property of your dialogs to your PrintDocument.

     

    • Marked as answer by Jing0Moderator Saturday, November 20, 2010 5:13 PM
    Tuesday, November 09, 2010 7:38 PM
  • I can't believe I missed that setting. Thanks so much for pointing that out for me! That did the trick with the margins.
    Joining the <Dark Side>
    Wednesday, November 10, 2010 11:54 PM