Home
Virtual Image Printer DriverMiraplacid Publisher converts documents to images
Virtual Text Printer DriverMiraplacid Text Driver extracts text from documents
PostScript Printer DriverMiraplacid PostScript Driver prints documents with your content inserted
Miraplacid Binary and Text DOM SDKMiraplacid Binary and Text DOM SDK - access to internal structure of a binary and text files
Common:   Login | Rules of forum | Register
Management:  New topic | Close topic | Move topic | Delete topic
  

Miraplacid Forum >> Software Development >> C# DOTNET Animation - Need Double BufferingModerator:XMan

Author Topic:  C# DOTNET Animation - Need Double Buffering
Sly
Member

From: Canada
posted 2004-05-08 07:35:16 Reply -Delete

I have written a program on C# .NET
There is a panel and OnPaint handler.
I invalidate it OnTimer, so it is kind of animation.
The problem is - it is blinking. I guess I need some nind os double buffering.
I set mypanel.SetStyle UserPaint, AllPaintingInWmPaint, and DoubleBuffer just like
MSDN recommends. It helps a bit on Win2000 and XP, but does not help on Win98.
I know how to implement the double buffering in the regular Win32 GDI (using Device Context)
So should I call Graphics.GetHdc and do something with it? How?

theory
Member

From: Suomi
posted 2004-05-08 08:48:27 Reply -Delete

Built-in DOTNET double buffering is suxx. No, you do not need GetHdc.
Instead, you need a bitmap object.
First, add a bitmap object to your class

private Bitmap m_bmp;

Then create it in Form_Load (make sute it fit to your panel)

m_bmp=new Bitmap(panel_width,panel_height);

then in panel_Paint

Graphics g=e.Graphics;
Graphics gm=Graphics.FromImage(m_bmp);

gm.Clear(Color.White); // or whatever your background is
gm.FillRectangle(Brushes.black,my_rect); // make your drawing here

g.DrawImageUnscaled(m_bmp,0,0);
gm.Dispose();

Sly
Member

From: Canada
posted 2004-05-08 09:25:57 Reply -Delete

Are you sure? It is blinking even more!

theory
Member

From: Suomi
posted 2004-05-08 09:53:58 Reply -Delete

May be it is background re-painting...

Try this:

- add class

public class NoBackPanel : Panel {
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//Don't allow the background to paint
}
}
- change your panel type from Panel to NoBackPanel

this.m_panel = new NoBackPanel(); //System.Windows.Forms.Panel();

Sly
Member

From: Canada
posted 2004-05-08 10:21:46 Reply -Delete

Wow! Thank you! Wonderful!

tunde
Member

From: nigeria
Web-page
Email
posted 2006-07-12 11:19:04 Reply -Delete

well i like suomi's stuff
but mine is rather different
i tried to make a dynamic movement of my label.text object by decrementing label.location.x parameter using a timer object
the label is moving vertically as required but i noticed a flikering\blinking effect
how do i control this
what is it about double buffering
suggest any possible approach

Yancho
Member

Email
posted 2007-12-20 19:37:24 Reply -Delete

this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer, true
);

Your message:
Name, password:
Go to category:  

Technical Support

Copyright © Miraplacid, 2003 - 2024