如何使标签的背景色更新更快?
编辑:
我已经找到了解决方法。现在,在 MouseEnter
上,我将焦点设置到按钮,并将 MouseOverBackColor
更改为按钮当前的 BackColor
;我还有一个用于 GotFocus
的事件处理程序(在按钮的父容器中),它会相应地更改 BackColor
。我不知道为什么会这样,但我只是让它在这个特定的组合中工作。再次,我正在寻找更好的方法来做到这一点,因此请跟上答案。
我进行了按钮覆盖,并且文本属性现在覆盖为自定义子标签。问题是我将样式应用于按钮(焦点/鼠标输入时颜色发生变化)。
我希望标签相应地改变它的颜色,到目前为止我已经通过两种方式实现了这一点:
- 将标签的
BackColor
设置为Transparent
- 覆盖
OnMouseEnter
> 和OnMouseLeave
也相应地更改标签的BackColor
。
他们都工作;唯一的问题是更改标签的 BackColor
时有轻微的延迟;当按钮的 BackColor
更改时,这会导致图形出现轻微撕裂。 这不是什么大问题,但有点烦人;我将不胜感激您给我的任何有用的建议。
EDIT:
I have managed a workaround. Now on MouseEnter
, I set the focus to the button, and I change the MouseOverBackColor
to the button's current BackColor
; I also have an event handler (in the parent container of the button) for GotFocus
that changes the BackColor
accordingly. I have NO idea why this works this way but I have only gotten it to work in this particular combination. Again, I am looking for better ways to do it so keep it up with the answers.
I made a Button override and the Text property now overrides to a custom child Label. The problem is I have styles applied to the button (color changing on focus/mouse enter).
I would like the Label to change it's color accordingly and I have achieved this in two ways so far:
- Set the label's
BackColor
toTransparent
- Override the
OnMouseEnter
andOnMouseLeave
to also change the Label'sBackColor
accordingly.
They both work; the only problem is there is a slight delay when changing the BackColor
of the Label; this result to a little tearing in graphics when the Button's BackColor
changes.
This isn't such a big deal but it is a little annoying; would appreciate any useful advice you would bestow upon me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您的应用程序处理 Windows 消息泵的频率或它的空闲程度,您可能需要调用 Control.Update() 来强制 .NET 立即更新控件的绘制。
http://msdn.microsoft.com/en -us/library/system.windows.forms.control.update.aspx
depending upon how frequently your application processes the windows message pump or how idle it is, you may need to call Control.Update() to force .NET to update the painting of the control immediately.
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.update.aspx