winform showdialog没有返回值

时间:2015-08-01 04:57:52

标签: c# winforms

enter image description here点击功能和返回值功能的主要表单

 private void xButton9_Click(object sender, EventArgs e)
        {
            Form Child_frm = new Select_doctor();
            Child_frm.ShowDialog(this);
          //  if()
            {
                using (var form = new Select_doctor())
                {
                    string val = form.ReturnValue1;            //values preserved after close
                    string dateString = form.ReturnValue2;
                    MessageBox.Show(form.ReturnValue1);
                }
            }

        }

点击网格表格中的子表格

public partial class Select_doctor : Form
    {
        public Select_doctor()
        {
            InitializeComponent();
            int Userid=Helper.ReadFromJsonUser_id("login.json");
            MessageBox.Show(Userid.ToString());


        }

        private void Grid_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Object row = this.Grid.Rows[e.RowIndex].Cells["Sl"].Value;

            Visual_aid_new.GetDoctorNmae(Convert.ToInt32(row.ToString()));
            this.Cus = 100;
            this.ReturnValue1 = "Something";
            this.ReturnValue2 = DateTime.Now.ToString();
            using (var form = new Visual_aid_new(0, 0, 0, Convert.ToInt32(row.ToString())))
            {

                form.Number = 10;

                MessageBox.Show(ReturnValue1);
                MessageBox.Show(ReturnValue2);
            }
            this.Close();
          //  var myForm = new Visual_aid_new(0,0,0,Convert.ToInt32(row.ToString()));

        }




        public  string ReturnValue1 { get; set; }
        public  string ReturnValue2 { get; set; }

        private int number = 0;
        public int Cus
        { get { return number; } set { number = value; } }
    }

问题是字符串没有返回主要功能;任何人都可以帮我解决。附上所有代码请检查

1 个答案:

答案 0 :(得分:1)

要根据Form访问自定义类的属性,您需要将Child_frm定义为Select_doctor而不是其基类Form。您还需要从您调用Select_doctor的{​​{1}}实例中读取返回的值。您在Show_Dialog()的全新实例中寻找值。

Select_doctor