This is a migrated thread and some comments may be shown as answers.
Print a picture from a picturebox
1 Answer 25 Views
This is a migrated thread and some comments may be shown as answers.
Roh
Top achievements
Rank 1
Roh asked on 26 Jan 2019, 03:57 PM

Hi.

I have a problem.

How can print a picture from a picturebox?

How can put correct object in Associateobjet to print it?

1 Answer, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 28 Jan 2019, 09:17 AM
Hi Roh,

The RadPrintDocument can only be used with RadControls implementing the IPrintable interface. This is also the type of the AssociatedObject property. If you want to use it with a standard picture box, you will need to inherit it and implement the interface similarly as demonstrated here: https://docs.telerik.com/devtools/winforms/telerik-presentation-framework/printing-support/how-to/create-prinatble-panel.

Please also check my code snippet below: 
public class PrintablePictureBox : PictureBox, IPrintable
{
    public int BeginPrint(RadPrintDocument sender, PrintEventArgs args)
    {
        return 1;
    }
 
    public bool EndPrint(RadPrintDocument sender, PrintEventArgs args)
    {
        return true;
    }
 
    public Form GetSettingsDialog(RadPrintDocument document)
    {
        return new PrintSettingsDialog(document);
    }
 
    public bool PrintPage(int pageNumber, RadPrintDocument sender, PrintPageEventArgs args)
    {
        Bitmap bmp = new Bitmap(this.Width, this.Height);
        this.DrawToBitmap(bmp, new Rectangle(Point.Empty, this.Size));
        args.Graphics.DrawImage(bmp, Point.Empty);
 
        return false;
    }
 
 
    public void Print()
    {
        RadPrintDocument doc = this.CreatePrintDocument();
        doc.Print();
    }
 
    public void PrintPreview()
    {
        RadPrintDocument doc = this.CreatePrintDocument();
        RadPrintPreviewDialog dialog = new RadPrintPreviewDialog(doc);
         
        dialog.ShowDialog();
    }
 
    private RadPrintDocument CreatePrintDocument()
    {
        RadPrintDocument doc = new RadPrintDocument();
        doc.AssociatedObject = this;
        return doc;
    }
}

I hope this will help.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Asked by
Roh
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or