// Create a new PictureBox control PictureBox picBox = new PictureBox(); // Set the image to be displayed in the control picBox.Image = new Bitmap("image.jpg"); // Set the size and position of the control on the form picBox.Size = new Size(300, 200); picBox.Location = new Point(10, 10); // Add the control to the form's Controls collection this.Controls.Add(picBox);
// Create a new Panel control Panel panel = new Panel(); // Override the control's OnPaint method to draw a custom shape protected override void OnPaint(PaintEventArgs e) { Graphics graphics = e.Graphics; graphics.FillRectangle(Brushes.Blue, new Rectangle(10, 10, 100, 50)); graphics.DrawEllipse(Pens.Red, new Rectangle(50, 70, 80, 60)); } // Set the size and position of the control on the form panel.Size = new Size(200, 200); panel.Location = new Point(10, 10); // Add the control to the form's Controls collection this.Controls.Add(panel);Package library: The System RenderControl in C# is part of the .NET Framework Class Library, which is a core library of classes and APIs provided by Microsoft for .NET developers.