Winform Reports for .NET
   Home
   Product Comparison
   Products
     PrintForm .NET
     PrintControls .NET
     PrintAdapters .NET
     PrintPreviewDialog .NET
     Localizer ASP.NET
     WebExtenders ASP.NET
   Downloads
     Free Trial Versions
     Upgrades
   Documents & Papers
   Purchase
   Support Index
   Press Releases
   Contact Us
   Privacy Statement
 
 
 
Go to TMG Development Ltd Website
Microsoft Certified Partner

HowTo: Dyamically Set the Picture on a PrintControls PictureBox

ID: W3298002

 

Background

The PrintControls PictureBox control exposes a Picture property of type TMGDevelopment.Windows.Forms.Picture. As a result you cannot directly assign a System.Drawing.Image reference into it. This article explains how to dyanmically set the Picture from code.

Setting the PictureBox.Picture from an Existing Image Object

To set the PictureBox.Picture from an existing Image object you need to construct a new TMGDevelopment.Windows.Forms.Picture based on the Image as follows. Note that you need to specify whether the Image is Bitmap based (gif, jpg, bmp etc), or Metafile based (emf, wmf etc) using the correct TMGDevelopment.Windows.Forms.PictureFormat enum in the second parameter.

C# Code Sample:

// this would be an Image from elsewhere in your code:
Image img = new Bitmap(@"C:\testimage.gif");
// set the new Picture based on the given Image into the PictureBox:

this.pictureBox1.Picture = new TMGDevelopment.Windows.Forms.Picture(img, TMGDevelopment.Windows.Forms.PictureFormat.Bitmap);


Setting the PictureBox.Picture from a File

To set the PictureBox.Picture from a file you need to construct a new TMGDevelopment.Windows.Forms.Picture based on the file as follows. Note that you need to specify whether the Image is Bitmap based (gif, jpg, bmp etc), or Metafile based (emf, wmf etc) using the correct TMGDevelopment.Windows.Forms.PictureFormat enum in the second parameter.

C# Code Sample:

// set the new Picture based on the given file into the PictureBox:
this.pictureBox1.Picture = new TMGDevelopment.Windows.Forms.Picture(@"C:\testimage.gif", TMGDevelopment.Windows.Forms.PictureFormat.Bitmap);


 

Last updated 04-Aug-2019