我将 ButtonRenderer.DrawButton
用于 DataGridView 中带有带图像按钮的列,我对何时应使用每个 PushButtonState
值很感兴趣。
Here是官方文档。它说:
Default
- The button has the default appearance.Disabled
- The button is disabled.Hot
- The button is hot.Normal
- The button has the normal appearance.Pressed
- The button is pressed.
我不太理解的是Default
和Normal
。这两个角色有什么区别?在下面的屏幕截图中,这 2 个角色与传递给 ButtonRenderer.DrawButton
方法的 focused
bool
参数组合在一起。
最佳答案
关于默认状态
根据基于 Windows 的桌面应用程序的用户体验指南 button control :
The default command button is invoked when users press the Enter key. It is assigned by the developer, but any command button becomes the default when users tab to it.
在windows窗体中,要将一个按钮设置为窗体的默认按钮,可以将其设置为窗体的AcceptButton
。有关详细信息,请参阅 How to: Designate a Windows Forms Button as the Accept Button Using the Designer
关于其他州
如果你看一下ButtonStandardAdapter
其中负责绘制一个标准按钮,你会看到:
private PushButtonState DetermineState(bool up) {
PushButtonState state = PushButtonState.Normal;
if (!up) {
state = PushButtonState.Pressed;
}
else if (Control.MouseIsOver) {
state = PushButtonState.Hot;
}
else if (!Control.Enabled) {
state = PushButtonState.Disabled;
}
else if (Control.Focused || Control.IsDefault) {
state = PushButtonState.Default;
}
return state;
}
IsDefault
为设置为 Form
的 AcceptButton
的按钮返回 true
。
关于c# - PushButtonState.Default 和 PushButtonState.Normal 之间的逻辑区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54181803/