窗体间传值的方法

窗体间传值的方法:

如窗体1内的textbox内的内容要在窗体2label上显示

方法一:

1.      窗体1内的重要代码:

FrM f = new FrM();

f.Show();

窗体2内的重要代码:

登录 d = (登录)Owner;

string a = d.name_textBox.Text;

this.toolStripStatusLabel2.Text = "当前用户: "+a;

在登录窗体内的name_textBox.TextModifies属性改为Public;

方法二:使用委托

窗体1

public delegate void returnValue(DataSetd);

       //定义委托事件

       public static event returnValue returnValueEvent;

       //委托时间的函数

       public void doreurnValue(DataSet d)

       {

           returnValueEvent(d);

       }

        void FrM_returnValueEvent(DataSet d)

       {

           this.dataGridView1.Visible = true;

           this.dataGridView1.DataSource = d.Tables[0];

       }

private void 新建查询ToolStripMenuItem_Click(objectsender, EventArgs e)

       {

           Search s;

           s = new Search();

           returnValueEvent+=newreturnValue(FrM_returnValueEvent);

           s.Show();

           s.MdiParent = this;

           this.dataGridView1.Visible = false;

           

       }

窗体2

private void button1_Click(object sender,EventArgs e)

       {

               bool a=radioButton1.Checked;

               bool b=radioButton2.Checked;

               bool c=radioButton3.Checked;

          if (a == true)

           {

                SqlConnection conn = newSqlConnection("server=.;database=Data_Collection;uid=123;pwd=123");

                string temper_search ="select * from Data where Temperature between '" + Tem_textBox2.Text+ "'and  '" + Tem_textBox1.Text+ "'";

                //SqlCommand cmd =newSqlCommand(temper_search, conn);

                conn.Open();

                SqlDataAdapter sa = newSqlDataAdapter(temper_search, conn);

                DataSet ds = new DataSet();

                sa.Fill(ds);

                FrM cx = new FrM();

                cx.doreurnValue(ds);

                conn.Close();

            }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值