我正在尝试从表单中获取值。我一直在尝试这个:如何从 C# 中的表单返回值?
它对我不起作用,也许我做错了什么,但在第二部分。
using (var form = new frmImportContact())
{
var result = form.ShowDialog();
if (result == DialogResult.OK)
{
string val = form.ReturnValue1; //ReturnValue1 is not an option...
string dateString = form.ReturnValue2;
//Do something here with these values
//for example
this.txtSomething.Text = val;
}
}
我无法显示“ReturnValue1”。它被宣布为公开,我还需要做什么?
这是我写的。我的子表格:
namespace ASPE.GUI.SensorWizard
{
public partial class PortsSensitivity : Form
{
public int ReturnValue1 { get; set; }
public PortsSensitivity()
{
InitializeComponent();
}
private void PortsBox_ValueChanged(object sender, EventArgs e, KeyPressEventArgs m)
{
this.ReturnValue1 = Convert.ToInt16(PortsBox.Value);
}
private void PortsSensitivity_Load(object sender, EventArgs e)
{
}
}
}
我的主要形式:
//Show Form (Number of Ports, Sensitivity)
Form Part3 = new ASPE.GUI.SensorWizard.PortsSensitivity();
DialogResult dr3 = new DialogResult();
dr3 = Part3.ShowDialog();
//Write Variables
int numofports = Part3.ReturnValue1; //Not an option.
//Close Form