0

フォームから値を取得しようとしています。私はこれを試しています: C#でフォームから値を返すには?

それは私にはうまくいきません。おそらく私は何か間違ったことをしているのですが、2番目の部分です。

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
4

1 に答える 1