【问题标题】:multiple user inputs to messagebox消息框的多个用户输入
【发布时间】:2014-05-25 00:54:04
【问题描述】:

我正在尝试将许多用户输入(文本框、组合框、日期选择器等)合并到一个消息框中,一旦单击按钮就会出现该消息框,但我不知道如何在一个消息框中完成所有这些操作。我只知道分别怎么做。

这是我的 Button_Click 代码

Dim s, sOut As String
    Dim x As System.Xml.XmlElement = cbEval.SelectedItem

    If x Is Nothing Then
        MsgBox("fill in Evaluator")
    Else
        s = "Evaluator Name: {0}"
        sOut = String.Format(s, x.InnerText)
        MsgBox(sOut)


    End If

当用户从 cbEval(组合框)中选择一个选项,然后单击“提交”按钮,他们选择的选项就会显示出来。我正在尝试将 DatePicker、CbEval、cbSelfEval、txtSelfComments、cbPeer、txtTotal 和 txtComments 添加到同一个 MessageBox 但不知道如何添加它们,尤其是 DatePicker(日历)。关于如何在 1 个消息框中添加更多内容有什么想法吗?

【问题讨论】:

    标签: wpf vb.net messagebox


    【解决方案1】:

    试试这样的:

    If x Is Nothing _
    OrElse String.IsNullOrEmpty(txtTotal.Text) _
    OrElse String.IsNullOrEmpty(CbEval.SelectedText) _
    OrElse DatePicker.Value Is Nothing Then
        MessageBox.Show("fill in Evaluator");
    Else
        sOut = String.Format("Evaluator Name: {0}" & Environment.NewLine() & _
               "Text: {1}" & Environment.NewLine() & _
               "CbValue: {2}" & Environment.NewLine() & _
               "Date3: {3}", _
               x.InnerText, txtTotal.Text, cbEval.SelectedText, DatePicker.Value.ToShortDateString())
        MessageBox.Show(sOut);
    End If
    

    当您比较您的DatePicker.Value 时,Nothing 将是可能的最小日期:01/01/1900

    【讨论】:

      【解决方案2】:

      *强调文字*也许是这样

          Dim s, sOut As String
          Dim x As System.Xml.XmlElement = cbEval.SelectedItem
      
          If x Is Nothing _
            Or String.IsNullOrEmpty(txtSelfComments.Text) _
            Or DatePicker.SelectedDate Is Nothing _
          Then
              MsgBox("fill in Evaluator")
          Else
      
              sOut = String.Format("Evaluator Name: {1}{0}Text2: {2}{0}" +
                     "Date3: {3}", Environment.NewLine, x.InnerText, txtSelfComments.Text, DatePicker.SelectedDate.ToString())
              MsgBox(sOut)
          End If
      

      对于 datePicker.SelectedDate.ToString() 可以使用 DateTime 格式 http://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx

      【讨论】:

      • 不会编译,并且给出的链接是西里尔文
      • 它们似乎都不能正确编译,并且在 if 语句之后使用 OR 会产生语法错误。
      • 已更正。它工作正常(组合框中没有您的 xmlElement)。
      猜你喜欢
      • 2019-06-01
      • 2012-06-10
      • 1970-01-01
      • 2017-12-04
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多