C# printing problem
By BARUNdeb
@BARUNdeb (1)
December 24, 2009 5:07pm CST
Hello all,
I am presently having a problem with printing in C#.
The problem is my customer provided me a pre printed paper and I
need to print value into some specific positions. But problem is C# for its
generic autofit to page nature dont let me doing this. Every time it is
decreasing whole page's size and also altering my value position into some
specific ration. Can anyone tell me how can I come over that problem.
This is my code
[CODE]
//I AM USING PrintDocument COMPONENT
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//panelPrintData IS A PANEL CONTAING MY PRINTING PICTUREBOX,TEXTBOX,COMBO AND OTHERS NEED TO PRINT
PrintDocument(panelPrintData, e);
}
public void PrintDocument(Panel p,PrintPageEventArgs e)
{
try
{
foreach (object obj in p.Controls)
{
if (obj is TextBox)
{
TextBox txt = (TextBox)obj;
e.Graphics.DrawString(txt.Text, new Font("Arial", 10, FontStyle.Regular), Brushes.Black, txt.Left , txt.Top );
}
if (obj is Utility.LSInterfaces.IImagePrintable)
{
Utility.LSInterfaces.IImagePrintable img = (Utility.LSInterfaces.IImagePrintable)obj;
e.Graphics.DrawImage(img.Picture, img.Left , img.Top , img.Width, img.Height);
}
if (obj is LogiSoftUserControl.ResizableComponent.ResizablePictureBox)
{
LogiSoftUserControl.ResizableComponent.ResizablePictureBox img = (LogiSoftUserControl.ResizableComponent.ResizablePictureBox)obj;
e.Graphics.DrawImage(img.Picture, img.Left , img.Top , img.Width, img.Height);
}
if (obj is PictureBox)
{
PictureBox img = (PictureBox)obj;
e.Graphics.DrawImage(img.Image, img.Left , img.Top , img.Width, img.Height);
}
}
}
catch (ArgumentNullException)
{ }
}
//THIS IS BUTTON FOR PRINT
private void btnPrint_Click(object sender, EventArgs e)
{
DialogResult r = printDialog1.ShowDialog();
if (r == DialogResult.OK)
printDocument1.Print();
}
[/CODE]
No responses
