P
Paul_Madden
I have a System.Windows.Forms.Form onto which I add a Panel (MyPanel)
directly derived from System.Windows.Forms.Panel.
Here are the important code fragments ...
public class MyPanel : Panel
{
.............................
public MyPanel () : base ()
{
this.SetStyle (ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle (ControlStyles.UserPaint, true);
}
protected override void OnPaintBackground (PaintEventArgs pe)
{
return;
}
protected override void OnPaint (PaintEventArgs pe)
{
using (Graphics g = this.CreateGraphics ())
.............
..........................................
The "OnPaint ()" routine uses the graphics context to draw some graphs etc.
Now, I have added the override to "OnPaintBackground ()" in order to see the
order of events which take place. In reality I do NOT override this method as
the standard Panel implementation does all I need it to do.
What happens is OnPaintBackground is entered and when exited On Paint is
entered.. So far so good.
When I simply let the app fly, every second I call Refresh () on the single
instance of the MyPanel object, this in turn ultimately invokes my On Paint
method which redraws my graphs. HOWEVER, the graph appears very quickly, then
is cleared again and the standard Form grey background replaces the graph
drawn in the panel.
Why is my Panel data displayed correctly but then instantly cleared. I send
the Refresh call directly to the MyPanel instance and not to the parent form.
I have moved the code logic from a combination that ALMOST worked perfectly,
ie the double buffering worked but wanted to remove the initial erase flicker.
In this previous working scneario, I had a Panel (not a derived Panel, ie
MyPanel), which sat directly on a CustomControl. Then the Refresh () produced
the graph data that persisted on the display until the second timer fired and
the data (plus flicker) was then redisplayed. WHY BY USING MY DERIVED PANEL
ON A FORM DOES MY CODE BEHAVE SO DIFFERENTLY TO THAT OF DISPLAYING A NATICE
PANEL ON A CUSTOMCONTROL.
So, once again, my graph appears for an instant, then is overwritten by the
standard Form Grey background colour. I do NOT have an active
OnPaintBackground and do NOT handle the associated event.
Many thanks for your time.
directly derived from System.Windows.Forms.Panel.
Here are the important code fragments ...
public class MyPanel : Panel
{
.............................
public MyPanel () : base ()
{
this.SetStyle (ControlStyles.DoubleBuffer, true);
this.SetStyle (ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle (ControlStyles.UserPaint, true);
}
protected override void OnPaintBackground (PaintEventArgs pe)
{
return;
}
protected override void OnPaint (PaintEventArgs pe)
{
using (Graphics g = this.CreateGraphics ())
.............
..........................................
The "OnPaint ()" routine uses the graphics context to draw some graphs etc.
Now, I have added the override to "OnPaintBackground ()" in order to see the
order of events which take place. In reality I do NOT override this method as
the standard Panel implementation does all I need it to do.
What happens is OnPaintBackground is entered and when exited On Paint is
entered.. So far so good.
When I simply let the app fly, every second I call Refresh () on the single
instance of the MyPanel object, this in turn ultimately invokes my On Paint
method which redraws my graphs. HOWEVER, the graph appears very quickly, then
is cleared again and the standard Form grey background replaces the graph
drawn in the panel.
Why is my Panel data displayed correctly but then instantly cleared. I send
the Refresh call directly to the MyPanel instance and not to the parent form.
I have moved the code logic from a combination that ALMOST worked perfectly,
ie the double buffering worked but wanted to remove the initial erase flicker.
In this previous working scneario, I had a Panel (not a derived Panel, ie
MyPanel), which sat directly on a CustomControl. Then the Refresh () produced
the graph data that persisted on the display until the second timer fired and
the data (plus flicker) was then redisplayed. WHY BY USING MY DERIVED PANEL
ON A FORM DOES MY CODE BEHAVE SO DIFFERENTLY TO THAT OF DISPLAYING A NATICE
PANEL ON A CUSTOMCONTROL.
So, once again, my graph appears for an instant, then is overwritten by the
standard Form Grey background colour. I do NOT have an active
OnPaintBackground and do NOT handle the associated event.
Many thanks for your time.