using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using WeifenLuo.WinFormsUI.Docking;
namespace KCTan
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form2.GetModel();
textBox1.Text = Form2.str;
}
private void Form1_Load(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show(dockPanel1);
f2.DockTo(dockPanel1, DockStyle.Fill);
}
}
}
#form2代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace KCTan
{
public partial class Form2 : DockContent
{
public Form2()
{
InitializeComponent();
}
public static String str = ""; //在窗体类里定义静态变量
public void GetValue()
{
str = textBox1.Text;
}
public static void GetModel()
{
Form2 GM = new Form2();
GM.GetValue();
}
}
}
窗体二里面定义一个Action, public Action callBack;窗体一调用窗体二的时候使用此回调函数并且返回string值。
在一个窗体里面,写一个public List XX = new List();
把这个窗体的值放到XX(.add)里面
再另一个窗体调用 窗体名.XX循环出来就ok了
form1里面定义的form2,form2的实例为f2,你如果想要form2里面TextBox的内容,不是通过f2.XXX就可以获取到了么。