From: Martin M on
Hello,

I use a picturebox to paint some graphical elements that have to be
repeatedly updated.
In short I do it like this:
public class myGraphics
{
public Bitmap offscreenBitmap;
private Graphics offscreenGraphics;
public myGraphics ()
{
...
offscreenBitmap = new Bitmap(width, height);
offscreenGraphics= Graphics.FromImage(offscreenBitmap);
...
}
.... more stuff and routines that load offscreenGraphics
}
public class Form1
{
....
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawImage (mypicture.offscreenBitmap,0,0);
}
private void timer1_Tick(object sender, EventArgs e)
{
call routines that paint to offscreenGraphics
pictureBox1.Refresh ();
}
}

Now when I have only some lines on the picture it looks good but when there
is a bit larger colored rectangle there is flickering even if the rectangle
doesn't move.
When I debug, I can see that calling Refresh clears the picturebox that is
then in pictureBox1_Paint repainted.
Is there a way to do it without first clearing the picturebox ie immedeatly
repainting it so that the rectangle is repainted by the rectangle and there
is no other contents displays at that location at any time?

To look at this graphics stuff a bit wider I would like to ask about the
bubble example (sorry, I can't find a link anymore but I could post it here
if desired) from microsft. How are things done there ? There is no Paint
event handler and no OnPaint in it. I would be lucky if someone could explain
how this works and if and how I could use something of it for my project.

Thank you very much for any help

Martin

From: James Parker on
>
>Hello,
>
>I use a picturebox to paint some graphical elements that have to be
>repeatedly updated.
>In short I do it like this:
>public class myGraphics
>{
>public Bitmap offscreenBitmap;
>private Graphics offscreenGraphics;
>public myGraphics ()
>{
>...
>offscreenBitmap = new Bitmap(width, height);
>offscreenGraphics= Graphics.FromImage(offscreenBitmap);
>...
>}
>.... more stuff and routines that load offscreenGraphics
>}
>public class Form1
>{
>....
>private void pictureBox1_Paint(object sender, PaintEventArgs e)
>{
>e.Graphics.DrawImage (mypicture.offscreenBitmap,0,0);
>}
>private void timer1_Tick(object sender, EventArgs e)
>{
>call routines that paint to offscreenGraphics
>pictureBox1.Refresh ();
>}
>}
>
>Now when I have only some lines on the picture it looks good but when there
>is a bit larger colored rectangle there is flickering even if the rectangle
>doesn't move.
>When I debug, I can see that calling Refresh clears the picturebox that is
>then in pictureBox1_Paint repainted.
>Is there a way to do it without first clearing the picturebox ie immedeatly
>repainting it so that the rectangle is repainted by the rectangle and there
>is no other contents displays at that location at any time?
>
>To look at this graphics stuff a bit wider I would like to ask about the
>bubble example (sorry, I can't find a link anymore but I could post it here
>if desired) from microsft. How are things done there ? There is no Paint
>event handler and no OnPaint in it. I would be lucky if someone could explain
>how this works and if and how I could use something of it for my project.
>
>Thank you very much for any help
>
>Martin
>
>

You might want to trying looking at this (Double Buffering) http://msdn.microsoft.com/en-us/library/3t7htc9c.aspx

Hope this helps.

j1mb0jay

-----------------------------------
Posted @ http://www.dotnethelp.co.uk
From: Martin M on
Hello James,

Thank you for this link.
Is this also true for a Win CE project?
With these I get compiler errors:
Form1.DoubleBuffered = true;
picturebox1.DoubleBuffered = true;
DoubleBuffered = true;
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

I am using System.Windows.Forms

Did I forget something?

Thank you for any help

Martin

From: TDC on
If you are blitting an image over the whole control surface you
generally override OnPaintBackground with a no-op. It is the
OnPaintBackground that clears the surfcae to the bacground color in
preperation for it to be rendered in the Paint.


On May 12, 5:11 pm, Martin M <Mart...(a)discussions.microsoft.com>
wrote:
> Hello James,
>
> Thank you for this link.
> Is this also true for a Win CE project?
> With these I get compiler errors:
> Form1.DoubleBuffered = true;
> picturebox1.DoubleBuffered = true;
> DoubleBuffered = true;
> SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
>
> I am using System.Windows.Forms
>
> Did I forget something?
>
> Thank you for any help
>
> Martin