如何让禁用的 ToolStripButton 为其图像绘制彩色?
我们有一个按钮允许用户“锁定”表单。 不允许用户“解锁”表单,因此当按下该按钮时,我们希望禁用该按钮,以便用户收到适当的视觉反馈。
然而,客户报告说,灰色的“锁定”图标向他们表明表单未锁定,因此我们希望以按下状态显示按钮,但图标为彩色,即使该按钮已禁用。
我们如何做到这一点,以绝对最少的覆盖绘画量?
We have a button which allows users to 'lock' a form. Users are not permitted to 'unlock' the form, so when pressed, we want the button to be disabled, so that the user receives appropriate visual feedback.
However, the customer reports that the greyed 'lock' icon suggests to them that the form is not locked, so we would like to display the button in a pressed state, but with the icon in colour, even though the button is disabled.
How do we do that, with the absolute minimum amount of overridden painting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
事实上我不同意这种做法。 您的客户可能有正确的观点,但我认为他们没有正确的修复建议。 您应该寻找其他方法使表单显示为“锁定”。 更改边框或字体颜色、出现大挂锁图标或从打开变为关闭等。按钮看起来一定是这样,因为这是用户所期望的。 如果您有一个看起来像是已启用的禁用按钮,这会让用户感到困惑,他们可能不明白为什么他们无法单击它。
Actually I disagree with the approach. Your customer might have a valid point, but I don't think they have the correct suggestion for the fix. You should look into other ways to make the form appear "locked". Changing borders or font colours, having a big padlock icon appear or change from open to closed etc. Buttons look a certain way because that's what users expect. If you have a disabled button that looks like it might be enabled, that's going to confuse users who might not then understand why they can't click it.
您可以将
ToolStripButton Image
设置为BackgroundImage
然后将
DiplayStyle
设置为None
。无论按钮
Enabled
值是什么,图片都应保持彩色。You can set the
ToolStripButton Image
asBackgroundImage
and then set the
DiplayStyle
toNone
.The picture should stay in colour no matter what's the button
Enabled
value.几周前我就遇到过这种情况,这个问题没有答案,所以这是我 4 年后的解决方案:
在许多情况下,我使用此解决方案重新绘制 ToolStripButton:禁用、选中、选择
两个好帮助我的示例:
http://tutorials. csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Customizing_a_Renderer
http://jskiles1.wordpress.com/2009/08/22/33/)
ToolStrip 类:
CustomRenderer 类:
问题是要知道 ToolStripButton 中所有元素的正确位置,这就是我在每种情况下绘制 ToolStripButton 的原因
I was in this case few weeks ago and this question doesn't have an answer, so this is my solution 4 years later :
I'm using this solution to repaint the ToolStripButton in many cases : disabled, checked, selected
Two good examples who helped me :
http://tutorials.csharp-online.net/Tool,_Menu,_and_Status_Strips%E2%80%94Customizing_a_Renderer
http://jskiles1.wordpress.com/2009/08/22/33/)
ToolStrip class :
CustomRenderer class :
The problem is to know the correct position of all elements in your ToolStripButton , that's why I drawn the ToolStripButton in every cases
另一种方法:根本不设置
button.Enabled = false
。 只需设置button.Checked = true
或false
,当有人单击按钮时测试Checked
状态并执行您所做的任何操作。 然后按钮将按照您想要的方式运行并保持颜色。Another way: don't set the
button.Enabled = false
at all. Just set thebutton.Checked = true
orfalse
and when someone clicks on the button test for theChecked
state and do whatever you do. The button will then function as you want and stay colored too.