【问题标题】:Switch case with an enum for button and labels [closed]带有按钮和标签枚举的开关盒[关闭]
【发布时间】:2017-08-21 03:22:49
【问题描述】:

我需要使用带有枚举的开关盒。 我有 7 个按钮和 7 个标签。第一个按钮被启用,其他按钮被禁用。 在我单击第一个按钮后,它应该被禁用,第二个应该被启用。 我该怎么做?

【问题讨论】:

  • 你能澄清你的问题吗?也许提供一个代码示例?

标签: c# winforms button switch-statement label


【解决方案1】:

假设您要声明一个枚举来跟踪您启用了哪个按钮,例如:

public enum Buttons
{
  b1, b2, b3, b4, b5, b6, b7
}
Buttons CurrentButton = Buttons.b1;

然后您可以执行以下操作:

switch (CurrentButton)
{
    case Buttons.b1:
        button1.Enabled = false;
        button2.Enabled = true;
        CurrentButton = Buttons.b2;
        break;
    case Buttons.b2:
        button2.Enabled = false;
        button3.Enabled = true;
        CurrentButton = Buttons.b3;
        break;
    {...}
}

不确定这是否是您的思考过程,但这是一种方法。但是,我会建议其他不使用枚举的方法。

【讨论】:

    猜你喜欢
    • 2022-12-28
    • 1970-01-01
    • 1970-01-01
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    相关资源
    最近更新 更多