How to paint embedded controls.
-
I have a user control that I would like to embed win forms controls in (for example System.Windows.Forms.Button) I would like to embed the control in a control that is a property on my user control I do not know how to then make the embedded control paint so that the user can see it. public class SideBarMenu : UserControl { public class MyMenuItem : Control { public bool isActive = false; } // ... other code omitted protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); //what do I do to paint the child controls //that can be contained in a MyMenuItem } } public class Test1 { public static void Test() { SideBarMenu mnu = new SideBarMenu(); MyMenuItem i = mnu.AddMenuItem("Hello"); Button b = new Button(); b.Text = "button1"; i.Controls.Add(b); } }
-
I have a user control that I would like to embed win forms controls in (for example System.Windows.Forms.Button) I would like to embed the control in a control that is a property on my user control I do not know how to then make the embedded control paint so that the user can see it. public class SideBarMenu : UserControl { public class MyMenuItem : Control { public bool isActive = false; } // ... other code omitted protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); //what do I do to paint the child controls //that can be contained in a MyMenuItem } } public class Test1 { public static void Test() { SideBarMenu mnu = new SideBarMenu(); MyMenuItem i = mnu.AddMenuItem("Hello"); Button b = new Button(); b.Text = "button1"; i.Controls.Add(b); } }
Hello Maybe I'm not following you! So forgive me if I stray. You don't have to worry about painting any controls inside your custom control. Just define their sizes and locations and they will draw themselves. You have only to paint your control to be viewd properly to the user, and of course to have a valid size to view all sub-controls. So in the paint method you only have to paint your control, maybe would want to refresh() or invalidate() all sub-controls and they will draw themselves. Another event you might want to handle is AddedControl. Have a look at it on MSDN. Regards:rose: