ToolStripButton“重置外观” /“火假事件”
我有一个执行操作的 ToolStripButton。用户单击该按钮,该按钮将被禁用,以防止该操作被执行两次。操作完成后,按钮将重新启用。一切都很完美......除了:
因为按钮被禁用,所以它不会触发“MouseLeave”事件,因此按钮的外观不会更新。为了绝对清楚,当鼠标进入 ToolStripButton 时,该按钮以橙色突出显示(默认情况下),周围有一个黑框。当我重新启用该按钮时,该突出显示不会被删除。此时,鼠标光标早已脱离控件。将鼠标悬停在按钮上自然会通过重绘来修复按钮。
我想做的是 ToolStripButton 上的某种方法“重置”其外观。这样的方法甚至可能存在于 ToolStrip 上,但尽管进行了搜索,但我一直无法找到类似的方法。
作为替代方案,我可以直接在按钮上触发“鼠标离开”事件。据我所知,在 C# .NET 中没有办法轻松做到这一点。
此时的任何建议将不胜感激,我自然不想撕毁我的应用程序并更换工具条。
I have a ToolStripButton that performs an action. The user clicks the button and the button is disabled to prevent the action being performed twice. After the action is complete the button is re-enabled. It all works perfectly...except:
Because the button is disabled it does not fire the "MouseLeave" event and as a result the appearance of the button is not updated. To be absolutely clear, when the mouse enters a ToolStripButton the button is highlighted in orange (by default) with a black box around it. This highlight is not being removed when I re-enable the button. The mouse cursor is, by this time, long gone from the control. Mousing over the button naturally fixes the button by redrawing it.
What I would like to do would be some method on the ToolStripButton that "resets" its appearance. Such a method may even exist on the ToolStrip, but despite searching I have been unable to find anything like this.
As an alternative I could fire the "Mouse Leave" event on the button directly. As far as I know there is no way to easily do this in C# .NET.
Any advice at this point in time would be most appreciated, naturally I don't want to tear up my application and replace the tool strip.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(3)
在禁用 ToolStrip 或 ToolStripItem 之前:
private void RemoveHighlightFromToolStrip(ToolStrip toolStrip)
{
foreach (ToolStripItem item in toolStrip.Items)
{
if (item.Pressed || item.Selected)
{
item.Visible = false;
item.Visible = true;
}
}
}
您也可以隐藏和显示整个 ToolStrip,但这可能会影响表单中的其他控件(即,如果您有一些停靠的 DataGridView,它将被重绘)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更新:
我重现了你的问题,试图弄清楚!
除了在点击事件中重置样式之外,我没有找到更好的方法
希望这有帮助!
您尝试过 Control.Invalidate() 吗?
Update:
I reproduced your problem, trying figuring out!
I didn't get a better way other than reset the style in the click event
Hope this helps!
Have you tried Control.Invalidate()?