c# - PushButtonState.Default 和 PushButtonState.Normal 之间的逻辑区别是什么?

标签 c# .net winforms button

我将 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.

我不太理解的是DefaultNormal。这两个角色有什么区别?在下面的屏幕截图中,这 2 个角色与传递给 ButtonRenderer.DrawButton 方法的 focused bool 参数组合在一起。

screenshot

最佳答案

关于默认状态

根据基于 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 为设置为 FormAcceptButton 的按钮返回 true

关于c# - PushButtonState.Default 和 PushButtonState.Normal 之间的逻辑区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54181803/

相关文章:

java - 如何在 .NET 中解压缩使用 java.util.zip.Deflater 缩小的流?

c# - 显卡适配器的 PNPDeviceID 是否唯一?

c# - 混合 WPF 和 winforms 项目 DPI 意识

c# - 为实例字段分配静态字段不会将两者都指向同一个对象

.net - Wpf - 以主桌面为中心

c# - C#.NET 是否有类似于我的分配助手类?

c# - 如何正确使用实时优先级

c# - C# Entity-Framework 中对象模型的过滤数据

c# - 按字符串排序列表转换为int

c# - 谁将 app.config 复制到 app.exe.config?