tags:

views:

162

answers:

3

I have a control which the user can resize with the mouse. When they move the right side, I just change the width, and everything works fine.

However, when they move the left size, I have to change the Left and Width properties. The right hand side of the control visibly twitches, showing the old width in the new position.

It still twitches if I set both left and width at once using Bounds; whether or not I use SetStyle with any of UserPaint, Opaque, OptimizedDoubleBuffer, AllPaintingInWmPaint or ResizeRedraw; and whether or not it's double buffered. It still twitches if I call SuspendLayout()/ResumeLayout() on either the control or its parent.

How do I stop controls from twitching when I change their left positions and their widths?

+5  A: 

You might want to try calling Control.SuspendLayout() on the containing form before moving / resizing, then Control.ResumeLayout().

It sounds like no matter what mode you set the control to, some event that fires when you change the bounds is redrawing it before both values are set. It may have something to do with the form.

EDIT: I saw this similar question on SO, you mentioned you had already used SetStyle(), but maybe there is some combination of options you can choose that will give you the desired effect.

Hope that helps!

Zachary Yates
This is the correct way. Also, you can anchor control on the right egde rather than the left. But I suspect it's as much a psychological/physiological phenomenon as it is technical.
Joel Coehoorn
No joy, I'm afraid. And this isn't psychological - while moving the left side right, the control paints a small rectangle to its right; and when moving it right, a small rectangle is left unpainted.
Simon
A: 

Could this help? http://richardsbraindump.blogspot.com/2007/09/how-to-create-flicker-free.html

I dont know if you used SetStyle with those parameters.

If this isnt helping, Ill delete the answer othervise Ill add the code snippet from the url.

Stefan
A: 

Instead of doing a live resize, maybe showing a sizer/ghost rectangle would work better. Then when the user mouses up, resize the control once.

Here's an article explaining a Win32/C++ method.
http://www.dotnetheaven.com/Uploadfile/amitnabarro/resize_rt04082005085351AM/resize_rt.aspx

You might be able to use the control container's Graphics object to draw a bounding rectangle without a flicker.

Lloyd Cotten
I'm afraid that's not an option in this case.
Simon
no problem, just throwing out ideas. You never know what may or may not work in some cases.
Lloyd Cotten