Description:-
In
this article we will Create Print Page Set up in Windows form using
PrintPageSetup Control and using toolstript to open set Menus in Windows form.
Here I have created demo example to Create and Setup Print menu in Windows
form.
First
Drag PrintPreviewDialog and toolstript in your windows form. Now using
toolstript Control to Design your Menus in header to open and so we can click
then Print Preview form will open to setup print page.
Now
Drag PrintDoument Control in your webpage To Design Document for Print. After
Drag textbox control in your windows form to Set Text and Preview in page
setup. For font Control Here I have Drag font Dialog in windows form for style
up font in textbox. Here in Menu I have setup Font for setup font in Textbox Text.
After that I have Drag pageSetUpDialog for Setup page for Print.
Now
you are done with Designing here we have to Generate Event for When we select
on each button what we have setup in Menus so For generate Click event of that
label you have to select that label and from property windows go to event tab
and you have to double click on click to generate click event of that control
to perform action.
Now
Right click on label control and go to code to create action to perform for
that label.Here
I have Setup Page Setup code for Setup page.
private void bttnPageSetup_Click(object sender, EventArgs e) { pageSetupDialog1.Document = printDocument1; pageSetupDialog1.ShowDialog(); }
For font Dialog open and set stylish font in text box you can
create code for that.
private void bttnFont_Click(object sender, EventArgs e) { if (fontDialog1.ShowDialog() == DialogResult.OK) { textBox1.Font = fontDialog1.Font; } }
For Preview print you can see print page before print so for that
control I have created code below.
private void bttnPrintPreview_Click(object sender, EventArgs e) { printDocument1.DefaultPageSettings.Landscape = true; printPreviewDialog1.Document = printDocument1; printPreviewDialog1.ShowDialog(); }
For Print page here I have create code to print page and save
where ever you want.
private void bttnPrint_Click(object sender, EventArgs e) { printDocument1.Print(); }
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { printDocument1.DefaultPageSettings.Landscape = true; if (string.IsNullOrEmpty(textBox1.Text)) { return; } else { e.Graphics.DrawString(textBox1.Text, textBox1.Font, Brushes.Black, textBox1.Left + 5, textBox1.Top + 5);//position as needed } }
Thanks for comments.....