By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,483 Members | 3,312 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,483 IT Pros & Developers. It's quick & easy.

form.doublbuffered problem

P: n/a

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
Oct 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Steve,

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

--
Dave Sexton

"Steve" <cc******@bigpond.net.auwrote in message
news:qI*******************@news-server.bigpond.net.au...
>
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

Oct 24 '06 #2

P: n/a
so simple - many thanks

rgds,Steve

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:u8**************@TK2MSFTNGP05.phx.gbl...
Hi Steve,

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

--
Dave Sexton

"Steve" <cc******@bigpond.net.auwrote in message
news:qI*******************@news-server.bigpond.net.au...
>>
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.Re d);
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


Oct 24 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.