In some situations we need to print only the contents of the controls
Using the following code we can print the contents of the contorls.
for eg say we have a label and textbox and we need to print the values of the controsl
using System.Drawing.Printing; using System.Drawing;
private void button1_Click(object sender, EventArgs e) { PrintDocument demodoc = new PrintDocument(); PrintPreviewDialog printprvdialog = new PrintPreviewDialog(); demodoc.PrintPage += new PrintPageEventHandler(printevent); printprvdialog.Document = demodoc; printprvdialog.ShowDialog(); }
private void printevent(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.DrawString(label1.Text, new Font("Arail",10,FontStyle.Bold), Brushes.Black, 100,200); e.Graphics.DrawString(textBox1.Text, new Font("Arail", 10, FontStyle.Bold), Brushes.Black, 150, 300); }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|