如何使标签的背景色更新更快?

发布于 2024-10-18 12:54:09 字数 723 浏览 2 评论 0原文

编辑:

我已经找到了解决方法。现在,在 MouseEnter 上,我将焦点设置到按钮,并将 MouseOverBackColor 更改为按钮当前的 BackColor;我还有一个用于 GotFocus 的事件处理程序(在按钮的父容器中),它会相应地更改 BackColor。我不知道为什么会这样,但我只是让它在这个特定的组合中工作。再次,我正在寻找更好的方法来做到这一点,因此请跟上答案。

我进行了按钮覆盖,并且文本属性现在覆盖为自定义子标签。问题是我将样式应用于按钮(焦点/鼠标输入时颜色发生变化)。

我希望标签相应地改变它的颜色,到目前为止我已经通过两种方式实现了这一点:

  1. 将标签的 BackColor 设置为 Transparent
  2. 覆盖 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:

  1. Set the label's BackColor to Transparent
  2. Override the OnMouseEnter and OnMouseLeave to also change the Label's BackColor 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

非要怀念 2024-10-25 12:54:09

根据您的应用程序处理 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文