Psst! Did you know DevelopmentNow is a mobile web site design agency?

Contact us for help mobilizing your site, or to sign up for our beta Mobile Web SDK!
all groups > dotnet windows forms controls > april 2006 >

dotnet windows forms controls : Resize flickering with transparent control, help double buffering?


Kristopher Wragg
4/19/2006 8:19:42 AM
Hi,

I'm creating some controls that basically draw shapes with/without text
inside/outside etc, pretty customizeable shapes including square,
circle, star...

I'm having a problem when their anchors are set so they resize with the
parent control, they're flickering like mad and I cant seem to get them
to double buffer and resize nicely...

To get transperency to work correctly I've had to use:

protected override CreateParams CreateParams
{
[SecurityPermission(SecurityAction.Assert, UnmanagedCode = true)]
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}

Inside my constructor:

SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.UserPaint, true);

I've overridden OnPaintBackground so that it doesn't call
base.OnPaintBackground

I'm also using a backbuffer image so it only blits at the end of the
painting method, but it's still flickering like mad on resize, and the
painting isn't that complex, especially for the circle and square
shapes, FillRect, DrawRect, DrawString, thats about it

Anyone have any tips?

Most of my transperency code has come from
http://www.bobpowell.net/transcontrols.htm and a few other sites with
similar content, it's been a royal pain in the behind trying to get
such a simple thing as circles and stars to be drawn nicely on top of
forms with background images and such

thanks,
Kris Wragg
Bob Powell [MVP]
4/19/2006 7:36:38 PM
Using controls as a drawing object is a really bad idea.

They own their own windows and carry loads of baggage with them that you
don't need.

The ownership of a window means that they will flicker uncontrollably
because you cannot double-buffer outside of the target windows area. A panel
with child controls cannot be made to double buffer itself *and* it's
children for example.

The only way to do this correctly is to create a single control that does
all the drawing using a form of retained mode graphics system.

See the animation example in Windows Forms Tips and Tricks for ideas.

--
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.



[quoted text, click to view]

Kristopher Wragg
4/20/2006 12:58:35 AM
Hi Bob,

I saw that example on your site already, but I dont think it meets my
needs as these are actually real controls with a fair bit of code
behind them.

They're not just painting shapes, they dynamically change via events
driven from an alert server, update their colour, text, sometimes
position... theres a fair bit of code behind them.

Also they're part of a product that will allow customers to drag these
onto a "canvas" and create dynamic views with various other components,
which they can select these controls and change the properties as to
how they react and change.

Is there no way to double buffer a control that uses transperancy then?
So far I've managed to stop the flickering at the expense of it not
updating till the user stops resizing the parent by setting a flag when
resize occurs and then not setting it to true (to paint) until
Application.Idle event fires... but I still don't like this approach as
it'd be nice for them to resize like everything else and not flicker!

many thanks for your site btw, it's helped me a lot with dipping my
toes into .NET coding :)

Kris Wragg
Bob Powell [MVP]
4/20/2006 8:07:42 PM
Having done it on many occasions before, the implementation choice of a
simple graphical object does not preclude that they fire events, react to
clicks, do drag and drop etc. It all has to do with the richness of the
implementation that you feel like writing.

Obviously you have to decide where the tradeoff works for you but don't
assume that just because they are not true windowed controls they have to be
brain-dead.

--
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.



[quoted text, click to view]

Frank Hileman
4/21/2006 6:28:31 AM
To reinforce Bob's advice, Controls are not the best way to do this, you
need custom graphical objects, and they can have all the features you need.
Control transparency simulation breaks down with double buffering.

Some more examples:
http://channel9.msdn.com/ShowPost.aspx?PostID=132172#132172

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

[quoted text, click to view]

AddThis Social Bookmark Button