1

我正在尝试开发一个自定义输入对话框。在其构造函数中,我想采用如下参数-

PromptType.Question
PromptType.Information
PromptType.Feedback
//etc....

private void buttonTest_Click(object sender, System.EventArgs e) 
{
   InputBoxResult result = InputBox.Show("Some title",PromptType.Question);
}

我该怎么做??

4

2 回答 2

3

你想要的是一个枚举:

public enum PromtType
{
    Question,
    Information,
    Feedback
}

public class InputBox
{
    public static void Show(PromtType type)
    {
        //...
    }
}

InputBox.Show(PromtType.Question);
于 2012-11-07T19:19:13.507 回答
1

您可以使用枚举方法,并在 switch 语句中捕获选定的选项

public enum PromtType
{
    Question,
    Information,
    Feedback
}

public class InputBox
{
    public static void Show(PromtType type)
    {
        switch(type)
       {
           case PromtType.Question:
           //do question things here
           break;
           case PromtType.Information:
           //do information things here
           break;
           case PromtType.Feedback:
           //do feedback things here
           break;
       }
    }
}

InputBox.Show(PromtType.Question);
于 2012-11-07T19:28:24.677 回答