|
-
Jan 19th, 2006, 02:48 AM
#1
Thread Starter
Member
printing in C#
Hi, I need send to the printer a simple line and a bold line in C#. Why is so complicate?
It's so simple in VB:
VB Code:
Printer.FontBold = False
Printer.Print "Normal line"
Printer.FontBold = True
Printer.Print "Bold line"
How can I do the same thing in C#?
Can you give me an example on how to do this, pls?
-
Jan 19th, 2006, 04:35 AM
#2
Addicted Member
Re: printing in C#
I have just written this simple class that shows how to print text. Check this out...
Code:
public class MySimpleDocument : PrintDocument
{
private string _strLine1, _strLine2;
public MySimpleDocument(string line1, string line2)
{
_strLine1 = line1;
_strLine2 = line2;
this.DocumentName = "My Simple Document";
}
protected override void OnBeginPrint(PrintEventArgs e)
{
// Add code here to initialise any information used by the document
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
Font normalFont = new Font("Tahoma",10f);
Font boldFont = new Font("Tahoma",10f,FontStyle.Bold);
e.Graphics.DrawString(_strLine1,normalFont,Brushes.Black,10,10);
e.Graphics.DrawString(_strLine2,boldFont,Brushes.Black,10,30);
normalFont.Dispose();
boldFont.Dispose();
}
}
and then use this print it
Code:
MySimpleDocument doc = new MySimpleDocument(this.textBox1.Text, this.textBox2.Text);
this.printDialog1.Document = doc;
if(this.printDialog1.ShowDialog() == DialogResult.OK)
{
doc.PrinterSettings = this.printDialog1.PrinterSettings;
doc.Print();
}
doc.Dispose();
You dont need eyes to see, you need vision.
-
Jan 19th, 2006, 09:43 AM
#3
Thread Starter
Member
Re: printing in C#
Thanks, it was very useful your example.
I have printed my first page in C#. Now I am wondering how can I print the second page and the rest of them, because when my 'y' coordinate it's greater than the height of the page, it's ... game over.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|