更改左侧位置和宽度时,如何阻止控件抽动? [英] How do I stop controls from twitching when I change their left positions and their widths?

查看:23
本文介绍了更改左侧位置和宽度时,如何阻止控件抽动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控件,用户可以用鼠标调整它的大小.当他们移动右侧时,我只是改变了宽度,一切正常.

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.

但是,当他们移动左尺寸时,我必须更改 Left 和 Width 属性.控件的右侧明显抽动,在新位置显示旧宽度.

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.

如果我使用 Bounds 同时设置 left 和 width ,它仍然会抽搐;我是否将 SetStyle 与 UserPaint、Opaque、OptimizedDoubleBuffer、AllPaintingInWmPaint 或 ResizeRedraw 中的任何一个一起使用;以及它是否是双缓冲的.如果我在控件或其父控件上调用 SuspendLayout()/ResumeLayout(),它仍然会抽搐.

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?

推荐答案

您可能想在移动/调整大小之前尝试在包含表单上调用 Control.SuspendLayout(),然后调用 Control.ResumeLayout().

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.

我看到了这个类似的问题 SO,你提到你已经使用了 SetStyle(),但也许你可以选择一些选项组合来给你想要的效果.

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.

希望有帮助!

这篇关于更改左侧位置和宽度时,如何阻止控件抽动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆