|
Help! My application displays a lot of graphics (lines and text), and works fine on most computers. On one of these computers, when the application starts, the initial graphics display completes, the screen erases, and the graphcs are displayed again. This cycle never ends!
Here is basically what I do:
1. Define System.Windows.Forms.Panel panelView as my graphics display window. 2. Call the panelView.Invalidate() method. 3. Draw the graphics on panelView. The code for this is in panelView_Paint(object sender, PaintEventArgs e).
I saw that in MFC there is a method called OnEraseBackground() that can be overriden and then return TRUE from it to eliminate the window erasure. Is there something equivalent in C#? Is there another type of cure for what ails my application?
Thanks for your help. Mike
- Moved byHarry ZhuMSFTThursday, September 10, 2009 2:44 AM (From:Visual C# Express Edition)
- Moved byLing WangMSFT, ModeratorThursday, September 17, 2009 7:56 AM (From:Windows Forms General)
-
| | mikeondmsn Tuesday, September 08, 2009 2:16 PM | Hi, Try enabling double buffering on the form;
this
.DoubleBuffered = true;
in the constructor of the form should do it. That might help with the flickering.
The equivalent to the OnEraseBackground you talked about is the OnPaintBackground method which is overridable, but you'd have to build your own panel control (i.e inherit from panel) to be able to override this method on panel, so that's not likely to be a good solution for you.
You can also disable the background erasing by calling
panel.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
However, that method is protected so again you'd have to inherit from panel again to call it, so also not a great solution for you.
Hopefully the double buffering will help.
- Marked As Answer byHarry ZhuMSFTThursday, September 17, 2009 7:14 AM
-
| | Yort Thursday, September 10, 2009 3:18 AM | Hi,
As @Yort said, Double buffering is a good method.
How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls
http://msdn.microsoft.com/en-us/library/3t7htc9c.aspx
In windows form, you can catch WM_ERASEBKGND message. The WM_ERASEBKGND message is sent when the window background must be erased.
http://msdn.microsoft.com/en-us/library/ms648055(VS.85).aspx
The following thread tells about that.
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=6127
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. - Marked As Answer byHarry ZhuMSFTThursday, September 17, 2009 7:14 AM
-
| | Ling Wang Tuesday, September 15, 2009 12:54 PM | Please post code that reproduces the problem so that someone can take a look at it.
Mark the best replies as answers. "Fooling computers since 1971." | | Rudedog2 Tuesday, September 08, 2009 6:13 PM | Hi, As Rudy said , code that can show the problem may help us to see the problem. For the question relating to winform controls , I'm moving it to winform controlsforum. Thanks, Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. | | Harry Zhu Thursday, September 10, 2009 2:43 AM | Hi, Try enabling double buffering on the form;
this
.DoubleBuffered = true;
in the constructor of the form should do it. That might help with the flickering.
The equivalent to the OnEraseBackground you talked about is the OnPaintBackground method which is overridable, but you'd have to build your own panel control (i.e inherit from panel) to be able to override this method on panel, so that's not likely to be a good solution for you.
You can also disable the background erasing by calling
panel.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
However, that method is protected so again you'd have to inherit from panel again to call it, so also not a great solution for you.
Hopefully the double buffering will help.
- Marked As Answer byHarry ZhuMSFTThursday, September 17, 2009 7:14 AM
-
| | Yort Thursday, September 10, 2009 3:18 AM | Hi,
As @Yort said, Double buffering is a good method.
How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls
http://msdn.microsoft.com/en-us/library/3t7htc9c.aspx
In windows form, you can catch WM_ERASEBKGND message. The WM_ERASEBKGND message is sent when the window background must be erased.
http://msdn.microsoft.com/en-us/library/ms648055(VS.85).aspx
The following thread tells about that.
http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=6127
Best regards,
Ling Wang
Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. - Marked As Answer byHarry ZhuMSFTThursday, September 17, 2009 7:14 AM
-
| | Ling Wang Tuesday, September 15, 2009 12:54 PM |
|