0

I want to print a form. I have this code but I can't choose what printer to print and it prints with default printer. How can I resolve this?

void PrintImage(object o, PrintPageEventArgs e)
{
    int x = SystemInformation.WorkingArea.X;
    int y = SystemInformation.WorkingArea.Y;
    int width = this.Width;
    int height = this.Height;
    Rectangle bounds = new Rectangle(x, y, width, height);
    Bitmap img = new Bitmap(width, height);
    this.DrawToBitmap(img, bounds);
    Point p = new Point(100, 100);          
    e.Graphics.DrawImage(img, p);
}
private void button1_Click(object sender, EventArgs e)
{
    PrintDocument pd = new PrintDocument();
    pd.PrintPage += new PrintPageEventHandler(PrintImage);

    pd.Print();        
}
  • This looks like winforms, is that correct? I would also recommend listing at least one solution that you've tried and why/how it failed. – clarkitect Jul 06 '14 at 18:21

1 Answers1

0

The answer is from HERE

You have to use PrintDialog

 PrintDocument pd = new PrintDocument();
 pd.PrintPage += new PrintPageEventHandler(PrintPage);
 PrintDialog pdi = new PrintDialog();
 pdi.Document = pd;
 if (pdi.ShowDialog() == DialogResult.OK)
 {
     pd.Print();
 }
 else
 {
      MessageBox.Show("Print Cancelled");
 }

On 64-bit Windows and with some versions of .NET you may have to set pdi.UseExDialog = true; for the dialog window to appear.

Community
  • 1
  • 1
coolerfarmer
  • 385
  • 2
  • 9