Mega Code Archive

 
Categories / C# Tutorial / GUI Windows Forms
 

Add Image to PictureBox

using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; public class PictureBoxImageAdding : System.Windows.Forms.Form {   private System.ComponentModel.Container components = null;   private PictureBox picBox = new PictureBox();   public PictureBoxImageAdding()   {     InitializeComponent();     picBox.SizeMode = PictureBoxSizeMode.StretchImage;     picBox.Location = new System.Drawing.Point(64, 32);     picBox.Size = new System.Drawing.Size(50, 50);     picBox.Image = new Bitmap("yourFile.bmp");     Controls.Add(picBox);   }   protected override void Dispose( bool disposing )   {     picBox.Dispose();     if( disposing )     {       if (components != null)        {         components.Dispose();       }     }     base.Dispose( disposing );   }   private void InitializeComponent()   {     this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);     this.ClientSize = new System.Drawing.Size(292, 273);   }   [STAThread]   static void Main()    {     Application.Run(new PictureBoxImageAdding());   } }