private void Form1_Paint(object sender, PaintEventArgs e) { // Draw a rectangle on the form Rectangle rect = new Rectangle(50, 50, 100, 100); e.Graphics.DrawRectangle(Pens.Red, rect); }
private void pictureBox1_Paint(object sender, PaintEventArgs e) { // Draw an image on a picture box Image img = Properties.Resources.myImage; e.Graphics.DrawImage(img, new Point(10, 10)); }In this example, the Paint event of a PictureBox control is handled by drawing an image on the PictureBox using the Graphics object provided by the PaintEventArgs. The image is loaded from the resources of the project. Package Library: System.Windows.Forms.dll.