form.doublbuffered problem

S

Steve

I use the paint event to call an external object that will write text
and or drawings to the form - (to make it persistant)

If i have the form property DoubleBuffered set to true the text will
only occassionaly display on the form.
However when I set the doublebuffered property false everything is fine
(except that i get flicker).

If I put the code from the class into the actual paint event it works
fine in both cases,
I presume that the hidden 'other' buffer is not updated if the code is
outside the paint event.

Has anyone struck this problem or have a solution to this - ?
Note that i am calling a number of objects with virtual overridden Draw
methods from within the
forms paint method so placing the code in the forms paint event is not an
option

a sample of my code:

private void frmChart_Paint(object sender, PaintEventArgs e)
{
foreach (Indicator ind in Indicators) // a generic list<MyObjects>
{
ind.Draw();
}
}

The Indicator class + one inherited class

public class Indicator
{
public SolidBrush myBrush = new
System.Drawing.SolidBrush(System.Drawing.Color.Red);
public Graphics formGraphics;
public static int drawcount;
public frmChart IndicatorOwner;
public Rectangle rect = new Rectangle();
public string size = "Large";
public Indicator(frmChart C)
{
IndicatorOwner = C;
}
public virtual void Draw()
{
formGraphics = IndicatorOwner.CreateGraphics();
}

}
public class PriceIndicator : Indicator
{
public PriceIndicator(frmChart C) : base(C)
{
}
public override void Draw()
{
base.Draw();

Pen myPen = new Pen(System.Drawing.Color.Red);
formGraphics.DrawRectangle(myPen, rect); // THIS AND
String drawString = "Sample Text"; // THIS ONLY DISPLAYS SPASMODICALLY ON
THE FORM WHEN DOUBLEBUFFERED PROPERTY IS SET
}

rgds,Steve
 
D

Dave Sexton

Hi Steve,

Don't call CreateGraphics. Instead, pass in e.Graphics to your Draw method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top