zoukankan      html  css  js  c++  java
  • winform 窗体传值

    Form1中:我们要把一个文本传递给Form2窗体,假定为passText
                  public string passText
                  {
                       get{ return textBox1.Text;}
                  }      
                  Form1中还有个按钮button1在其点击事件中有:
                                 private void button1_Click(object sender,EventArgs e)
                  {
                                         Form2 f2 = new Form2();   //呃。。这个就不用说了
                          f2.Owner = this;  //设置附属,好搭关系~
                         f2.Show();   //看得出来撒
                  }
    Form2的对象中:
                假设有个文本框txtBox1,
                 private void form2_Load(object sender,EventArgs e)
                 {
                                        //通过目标窗体,找到拥有它的源窗体,得到的是一个object
                                         对象,要转换成Form1这个类型,就可以得到它的公有属性passText拉。
                     textBox1.Text = ((Form1)this.Owner).passText;
                                 }
    这样当我们打开Form2时,就会在其文本框中,显示Form1的文本框信息了(想要做到查询对话框显示选中文本的效果,只需要在把passText 的属性改成textBox.SelectedText即可.
    这种方法的主要好处是在于,我们能在目标窗体的对象中,找到源窗体的对象。而有别与上面两种情况。

  • 相关阅读:
    print 参数
    note
    action标签的属性说明
    Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
    润乾报表
    javax.naming.NameNotFoundException: Name ZKING is not bound in this Context 的问题
    Myeclipse2013安装svn插件
    Myeclipse2013的优化设置
    Myeclipse解析.classpath文件
    Struts
  • 原文地址:https://www.cnblogs.com/yangpeng-jingjing/p/4535081.html
Copyright © 2011-2022 走看看