3
Answers

Adding a Rectangle object to a Panel

ugp

ugp

17y
3.6k
1
I was able to add a button/label to a Panel like this; this.panel1.Controls.Add(this.button1); this.panel1.Controls.Add(this.label11); Works..OK! But, what I need is to add a Rectangle object to a Panel. I draw a Rectangle object; Graphics graph = this.CreateGraphics(); Pen penCurrent = new Pen(Color.Red); Rectangle Rect = new Rectangle(300, 50, 150, 75); graph.DrawRectangle(penCurrent, Rect); But when i do like this; this.panel1.Controls.Add(this.Rect); it gives an ERROR! ----- Says; Controls.Add() , works only for System.Windows.Forms.Control and CanNOT work with System.Drawing.Rectangle ----- So how can i achive this; add a Rectangle object to a Panel
Answers (3)