No double-buffering on a Panel?

B

Bit Twiddler

Is it true that double-buffering can only be performed on Form?

I would like to draw to a Panel, but it flickers like crazy when resized.

Thanks,
BT
 
B

Bob Powell [MVP]

You can derive your own class from panel or containercontrol and set double
buffering explicitly.

See Windows Forms Tips and Tricks for double-buffering info.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
B

Bit Twiddler

I guess I could subclass Panel and set all the doublebuffering stuff
manually, but then I won't be able to set the panel's properties at
designtime in the IDE.

If I want to be able to do that I have to create a UserControl? If so, how
do I ensure that all of the existing Panel properties show up in the
property pane?

Thanks,
BT
 
H

Herfried K. Wagner [MVP]

Bit Twiddler said:
Is it true that double-buffering can only be performed on Form?

I would like to draw to a Panel, but it flickers like crazy when resized.

Create a class that derives from 'Panel' and extend the constructor to
enable double-buffering:

\\\
Public Sub New()
Me.SetStyle( _
ControlStyles.ResizeRedraw Or _
ControlStyles.DoubleBuffer Or _
ControlStyles.AllPaintingInWmPaint, _
True _
)
Me.UpdateStyles()
End Sub
///
 
L

Lloyd Dupont

I guess I could subclass Panel and set all the doublebuffering stuff
manually, but then I won't be able to set the panel's properties at
designtime in the IDE.
false!
whatever class you derived or create it display well in the designer, using
parent information as well, where appropriate!
If I want to be able to do that I have to create a UserControl? If so,
how do I ensure that all of the existing Panel properties show up in the
property pane?
well you could inherit from ser control instead if you want.
you have nothing special to do to have good integration with the designer
 
B

Bit Twiddler

Lloyd Dupont said:
false!
whatever class you derived or create it display well in the designer,
using parent information as well, where appropriate!

Thanks for the response Lloyd. I am confused though. If I simply inherit
my class from Panel, how do I "drop" my new class on a form in the IDE
(there is no instance of my derived class in the toolbox).

Thanks,
BT
 
L

Lloyd Dupont

Thanks for the response Lloyd. I am confused though. If I simply inherit
my class from Panel, how do I "drop" my new class on a form in the IDE
(there is no instance of my derived class in the toolbox).
well, that's a good question ;-)

I could see 2 way of doing that:
1. drop a panel, edit the generated code by replacing the variable
declaration and creation (new MyClass()) by your fully qualified class name,
and that's it!
2. compile you code, then right click on the toolbox panel, choose add
items, browse for the assembly, load your debug/release/whatever assembly
(the one you are generated, right!), then your GUI controls (of this very
project) will be in your tool box! just uses them as you will of other
controls.
 

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