窗体:将子窗体的值赋值给父窗体的控件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/DeyuanYangjia1314/article/details/52105747
//父窗体打开子窗体的方法、同时接收子窗体传回来的值
 private void BtnAdd_Click(object sender, EventArgs e)
        {
            Sys_EMailCusCode cs = new Sys_EMailCusCode();
            cs.StartPosition = FormStartPosition.CenterScreen;
            cs.ShowDialog();
            if (cs.DialogResult == DialogResult.OK)
            {
                txtMsgType.Text = cs.GetCustomerID;
                cs.Close();
            }
        }
//子窗体
private void BtnSure_Click(object sender, EventArgs e)
        {
            string str = "";
            List<int> selectRows;
            selectRows = gridView1.GetSelectedRows().ToList();
            if (selectRows.Count > 0)
            {
                for (int i = 0; i < selectRows.Count; i++)
                {
                    if (i==0)
                        str = gridView1.GetDataRow(i)["CusCode"].ToString();
                    else
                        str = str +","+ gridView1.GetDataRow(i)["CusCode"].ToString();
                }
            }
            CustomerID = str;
            this.DialogResult = DialogResult.OK;
        }

        public string GetCustomerID
        {
            get 
            {
                return CustomerID;
            }
        }




                                    
展开阅读全文

窗体窗体的问题

06-28

我有3个窗体:form1,form2,form3。其中,form1为父窗体,form3为其子窗体。(不知道可否将form2页置为其子窗体?)还有一个模块Moudle1,用于把值从form2传递到form1中(不知是否不用模块,而有更好的方法?)rnform1有一个button,用于打开form2;form2中有一个botton,用于打开form3,我想打开form3时,对form1的某个文本框进行操作。rn代码为:rnrnModule Module1rn Public value As StringrnEnd ModulernrnPublic Class Form1rn Inherits System.Windows.Forms.Formrn Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loadrn Dim newform1 As New Form3rn newform1.MdiParent = Mern ' Dim newform As New Form2rn ' newform.MdiParent = Mern textbox1.text=value rnrn End SubrnrnPrivate Sub Form1_MdiChildActivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles myBase.MdiChildActivatern TextBox1.Text = valuern 'Me.TextBox2.Text = Me.ActivateMdiChild.textrn End SubrnrnEnd ClassrnrnrnPublic Class Form2rn Inherits System.Windows.Forms.Formrn Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickrn value = TextBox1.Textrn Dim newform As New Form3rn newform.Show()rn End SubrnEnd ClassrnrnrnPublic Class 3rn Inherits System.Windows.Forms.Formrn Dim newform As New Form2rn TextBox1.Text = valuernEnd Classrnrn现在的问题是:从form2里面调用form3时,form1的textbox1里面怎么也显示不出form2里面赋的value的值。而如果是由form1的form_load调用的form3的话,就可以。为何?rn但是我不能这样直接调用!该怎么做?rnrn谢谢rnrnrn 论坛

没有更多推荐了,返回首页