Custom Search

Monday, January 21, 2008

Adding information to the Print Page

This c# code lets you add an image to the print page.

using System;

using System.Collections;

using System.ComponentModel;

using System.Drawing;

using System.Drawing.Printing;

using System.Data;

using System.Windows.Forms;

Graphics g = e.Graphics;

g.PageUnit = GraphicsUnit.Millimeter;

System.Drawing.Image logo;

//Here you have to specify the location of the image

logo = System.Drawing.Image.FromFile("logo.gif");

//Locate the logo image on the location set on new Point

g.DrawImage(logo, new Point(155, 5));

Adding some text to the page:

String text = "Text to be added";

//You can set the font, type, location and many other features.

Font fontText = new Font("Times New Roman", 12, FontStyle.Regular);

g.DrawString(text , fontText, Brushes.Black , new Point(54, 4));

Drawing a line:

Pen pen= new Pen(Color.Gray);

//Set the begin and the end of the line.

e.DrawLine(pen,new Point(x1,y1),new Point(x2,y2));

No comments: