Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print a image 1

Status
Not open for further replies.

elinM

Programmer
Feb 12, 2004
15
NO
Hi.
I was wondring if any one know how to print a picture like a jpg or gif in C#..

Will be very thankful for any kind of help!

Best regards,
Elin
 
There are PrintDocument and Graphics classes.
Here is a small example:

private void printButton_Click(object sender, EventArgs e)
{
try
{
// Assumes the default printer.
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
pd.Print();
}
catch(Exception e)
{
MessageBox.Show("Error occurred while printing", e.GetType() + e.Message);
}
}

private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
// Draw image.
ev.Graphics.DrawImage(Image.FromFile("C:\\Program Files\\Images\\george.bmp"), ev.Graphics.VisibleClipBounds);
// Indicate that this is the last page to print.
ev.HasMorePages = false;
}
-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top