I am using a Control. I have added two Panels in it as i would like to draw the multiple panels over a control. i overrided OnPaint() method for those two panels, but OnPaint() method of the first panel added to the control alone called, OnPaint() method not called for the second panel that i added to the control.
Note: I have used the below code to redraw the surface to avoid flicker issues. If i remove the below codes from my sample, OnPaint() method called for the second panel, but the element drawn in the second panel is not in Visual. (i.e,) Not displayed.
SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.Selectable |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
How can i achieve multiple panels drawing on a single control? Thanks in advance.
Code:
public Class VContainer : Panel
{
public CPanel CPanel;
public SPanel SPanel;
public VContainer()
{
this.CPanel = new CPanel();
this.SPanel = new Spanel();
this.Controls.Add(Cpanel); **// first added Panel**
this.Controls.Add(SPanel);
}
protected override void OnMouseDown(MouseEventArgs e)
{
this.CPanel.Invalidate();
this.SPanel.Invalidate();
this.SPanel.Update();
}
}
public class CPanel : Panel
{
public CPanel()
{
// Used to redraw the surface to avoid flickering issues
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
}
**// OnPaint() called since Cpanel is added first to the VContainer**
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red, new Rect(0,0,50,50));
base.OnPaint(e);
}
}
public class SPanel : Panel
{
public SPanel()
{
// Used to redraw the surface to avoid flickering issues
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
}
**// OnPaint() method is not called while invalidating the Panel since the Spanel is added as second control to VContainer**
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Green, new Rect(0,0,50,50));
base.OnPaint(e);
}
}