【问题标题】:What button pressed inputbox C#按下了什么按钮输入框C#
【发布时间】:2013-06-03 11:19:24
【问题描述】:

我在 c# 中使用 Visual Basic 中的输入框,但我无法弄清楚我如何知道按下了哪个按钮。输入框返回已经写入的字符串。 我如何知道是单击了取消按钮还是单击了确定按钮?

非常感谢您的帮助,我没有找到答案:)

这是我尝试过的:

string notineName = Interaction.InputBox("Enter the notice name:", "Enter notice name", "");

如果你有其他的方法来做输入框(我想自己做,但我不知道如何返回被点击的按钮)请写在这里。

【问题讨论】:

    标签: c# button inputbox


    【解决方案1】:

    如果用户点击取消,则返回一个长度为零的字符串。

    尝试查看此文档。 MSDN

    【讨论】:

      【解决方案2】:

      您也可以使用对话框。

      InputDialog dialog = new InputDialog("Caption Here", "Label Text Here", "Default Textbox String");
      if (dialog.ShowDialog() == DialogResult.OK)
      {
          string result_text = dialog.ResultText;
          // use result_text...
      }
      else
      {
          // user cancelled out, do something...
      }
      

      这里的枚举结果决定了哪个按钮被选中。

      【讨论】:

      • 这个问题是针对 C# 的。 InputDialog 在 VB.net 之外不存在。
      【解决方案3】:
      string a;     
      a = Interaction.InputBox("message", "message");
      if (a.Length > 0)
      {
          comboBox2.Items.Add(a); 
          // ok
      }
      else
      {
          // cancel
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-17
        • 2013-08-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多