Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

winforms

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?

like image 374
Simon Avatar asked Dec 18 '25 16:12

Simon


1 Answers

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!

like image 55
Zachary Yates Avatar answered Dec 20 '25 06:12

Zachary Yates



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!