How to stop control from twitching when changing their left positions and their width?

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

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

It still twitches if I set both left and width at the same time using Bounds; regardless of whether I use SetStyle with any parameters UserPaint, Opaque, OptimizedDoubleBuffer, AllPaintingInWmPaint or ResizeRedraw; and whether or not this is double buffered. It still twitches if I call SuspendLayout () / ResumeLayout () either in the control or in its parent.

How to stop controls from twitching when changing their left positions and their width?

+3
source share
3 answers

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

It seems that regardless of the mode in which you set the control, some event that fires when the borders change changes over again before both values ​​are set. This may have something to do with form.

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

Hope this helps!

+5
source

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

I do not know if you are using SetStyle with these parameters.

If this does not help, I delete the othervise answer. I am adding a code snippet from the URL.

0
source

Instead of doing live resizing, perhaps showing a sizer / ghost rectangle will work better. Then, when the user pulls, resize the control once.

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

Perhaps you can use the Graphics object of the control container to draw a bounding rectangle without flickering.

0
source

All Articles