我有两个winform1,winform2
winform1中使用了树控件 定义了GetTreeText()方法得到选中Node的text问题是winform2 怎么去调用GetTreeText()方法,请大家赐教来者有分!

解决方案 »

  1.   

    form2 frm =new frm2();
    if (frm.ShowDialog(this).DialogResult==DialogResult.OK)
    {
     MessageBox.Show(frm.GetTreeText());
    }
      

  2.   

    to:helimin19(生存)
    我的本意是 
    winform1 是个父窗口
    winform2 是个搜索窗口
    就象记事本一样
    搜索结果选定树的Node
      

  3.   

    3tzjq(永不言弃) :
      这种方法不行
      他新建了一个winform1对象
      不能取得当前树选中的Node
      

  4.   

    直接调用就可以啊  使用你创建的winform1的实例的引用
      

  5.   

    可以考虑在winform2中设置一个public的属性,初始化winform2后给这个属性赋值。
      

  6.   

    给你一种方向设置  为 public static 然后在
    其它地方调用.... public  static string  s;调用时  类名.s 注意是是类名啊.
      

  7.   

    form1 :
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;namespace WindowsApplication3
    {
    /// <summary>
    /// Form1 的摘要说明。
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null;
    private System.Windows.Forms.Button button2;
    public static string s;  //注意这   public Form1()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if (components != null) 
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    this.button2 = new System.Windows.Forms.Button();
    this.SuspendLayout();
    // 
    // button2
    // 
    this.button2.Location = new System.Drawing.Point(104, 160);
    this.button2.Name = "button2";
    this.button2.Size = new System.Drawing.Size(80, 40);
    this.button2.TabIndex = 1;
    this.button2.Text = "button2";
    this.button2.Click += new System.EventHandler(this.button2_Click);
    // 
    // Form1
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Controls.Add(this.button2);
    this.Name = "Form1";
    this.Text = "Form1";
    this.Load += new System.EventHandler(this.Form1_Load);
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } private void Form1_Load(object sender, System.EventArgs e)
    {

    }
    private void button2_Click(object sender, System.EventArgs e)
    {
    s="100";  Form2 frm=new Form2();
           frm.Show ();
            
        
     
    }
    }
    }
    // form2 using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;namespace WindowsApplication3
    {
    /// <summary>
    /// Form2 的摘要说明。
    /// </summary>
    public class Form2 : System.Windows.Forms.Form
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.Container components = null; public Form2()
    {
    //
    // Windows 窗体设计器支持所必需的
    //
    InitializeComponent(); //
    // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
    //
    } /// <summary>
    /// 清理所有正在使用的资源。
    /// </summary>
    protected override void Dispose( bool disposing )
    {
    if( disposing )
    {
    if(components != null)
    {
    components.Dispose();
    }
    }
    base.Dispose( disposing );
    } #region Windows 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {
    // 
    // Form2
    // 
    this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
    this.ClientSize = new System.Drawing.Size(292, 273);
    this.Name = "Form2";
    this.Text = "Form2";
    this.Load += new System.EventHandler(this.Form2_Load); }
    #endregion private void Form2_Load(object sender, System.EventArgs e)
    {
    MessageBox.Show ("传过来的值为:"+Form1.s .ToString());
    }
    }
    }