V
VJ
I have a sample code.. below with my Print problem... I am not able to get
the Label on Image print at the right location..
VJ
private Label label4 = new Label();
Form1's Load...
label4.BackColor=Color.White;
label4.BorderStyle=BorderStyle.FixedSingle;
label4.Text = "label4";
label4.Location=new Point(300,1450);
label4.Size = new Size(50,50);
pictureBox1.Controls.Add(label4);
// pictureBox1 is a control on Form1, inisde Panel1
// with a large enough image to have scroll bars...
// the picturebox1.SizeMode = SizeMode.Normal
Button Click Event
PrintDocument printDoc = new PrintDocument();
printDoc.PrintPage+=new PrintPageEventHandler(printDoc_PrintPage);
PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog();
printPreviewDlg.Document = printDoc;
printPreviewDlg.ShowDialog();
private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap imageForPrinting = new Bitmap(pictureBox1.Width,
pictureBox1.Height);
using (Graphics graphicsImage = Graphics.FromImage(imageForPrinting))
using (DibGraphicsBuffer dib = new DibGraphicsBuffer())
// Create temporary screen graphics
using (Graphics graphicsForm = this.CreateGraphics())
// Create temporary graphics from the Device Independent Bitmap
using (Graphics graphicsTemp =
dib.RequestBuffer(graphicsForm, e.PageBounds.Width,
e.PageBounds.Height))
{
graphicsTemp.DrawImage(pictureBox1.Image,
e.PageBounds,
0, 0, pictureBox1.Width, pictureBox1.Height,
GraphicsUnit.Pixel);
// The below piece of code is not printing.. on the Print Documents.. I
know
// we have to transform points.. but How do we do that???
PointF labelLocation = new PointF(label3.Left, label3.Top);
graphicsTemp.DrawString(label3.Text, label3.Font,
new SolidBrush(Color.Black), labelLocation);
// Use the buffer to paint onto the final image
dib.PaintBuffer(graphicsImage, 0, 0);
// Draw this image onto the printer graphics,
// adjusting for margins
e.Graphics.DrawImage(imageForPrinting,
e.MarginBounds.Left, e.MarginBounds.Top);
}
}
the Label on Image print at the right location..
VJ
private Label label4 = new Label();
Form1's Load...
label4.BackColor=Color.White;
label4.BorderStyle=BorderStyle.FixedSingle;
label4.Text = "label4";
label4.Location=new Point(300,1450);
label4.Size = new Size(50,50);
pictureBox1.Controls.Add(label4);
// pictureBox1 is a control on Form1, inisde Panel1
// with a large enough image to have scroll bars...
// the picturebox1.SizeMode = SizeMode.Normal
Button Click Event
PrintDocument printDoc = new PrintDocument();
printDoc.PrintPage+=new PrintPageEventHandler(printDoc_PrintPage);
PrintPreviewDialog printPreviewDlg = new PrintPreviewDialog();
printPreviewDlg.Document = printDoc;
printPreviewDlg.ShowDialog();
private void printDoc_PrintPage(object sender, PrintPageEventArgs e)
{
Bitmap imageForPrinting = new Bitmap(pictureBox1.Width,
pictureBox1.Height);
using (Graphics graphicsImage = Graphics.FromImage(imageForPrinting))
using (DibGraphicsBuffer dib = new DibGraphicsBuffer())
// Create temporary screen graphics
using (Graphics graphicsForm = this.CreateGraphics())
// Create temporary graphics from the Device Independent Bitmap
using (Graphics graphicsTemp =
dib.RequestBuffer(graphicsForm, e.PageBounds.Width,
e.PageBounds.Height))
{
graphicsTemp.DrawImage(pictureBox1.Image,
e.PageBounds,
0, 0, pictureBox1.Width, pictureBox1.Height,
GraphicsUnit.Pixel);
// The below piece of code is not printing.. on the Print Documents.. I
know
// we have to transform points.. but How do we do that???
PointF labelLocation = new PointF(label3.Left, label3.Top);
graphicsTemp.DrawString(label3.Text, label3.Font,
new SolidBrush(Color.Black), labelLocation);
// Use the buffer to paint onto the final image
dib.PaintBuffer(graphicsImage, 0, 0);
// Draw this image onto the printer graphics,
// adjusting for margins
e.Graphics.DrawImage(imageForPrinting,
e.MarginBounds.Left, e.MarginBounds.Top);
}
}