单击按钮,在消息框中显示许多值

问题描述 投票:0回答:1

本质上是帐单摘要,当我单击按钮时,尝试在最后的文本框中显示摘要信息。如何以MessageBox.Show格式显示我拥有的所有信息(RadioButton,TextBoxes,CheckBoxes等)?

c# messagebox
1个回答
0
投票

我不知道您拥有多少信息,但是我可以说,您要做的就是获取内容的值并将其连接起来。

如果您有三个内容:

  • System.Windows.Forms.RadioButton
  • System.Windows.Forms.TextBox
  • System.Windows.Forms.CheckBox

将三个信息放入这样的字符串中:

var radioButtonInfo = radioButton.Checked ? "RadioButton checked" : "RadioButton not checked";
var textBoxInfo = textBox.text;
var checkBoxInfo = checkButton.Checked ? "CheckButton checked" : "CheckButton not checked";
var text = $"{radioButtonInfo}\n{textBoxInfo}\n{checkBoxInfo}";

最后,调用MessageBox.Show()显示它。

MessageBox.Show(text);
© www.soinside.com 2019 - 2024. All rights reserved.