是这样的,我有如下的代码:
主窗体:
namespace DataImport
{
public partial class MainFRM : Form
{
public ArrayList arlOrignal = new ArrayList();
public ArrayList arlTblDBsvr = new ArrayList();
public ArrayList arlTblDBName = new ArrayList();
public ArrayList arlTblDBUser = new ArrayList();
public ArrayList arlTblDBPsw = new ArrayList();
private void butTest_Click(object sender, EventArgs e)
{
DataImpDetailFRM frmChild = new DataImpDetailFRM();
frmChild.Show();
}
}子窗体:
namespace DataImport
{
public partial class ChildFRM : Form
{
private MainFRM frmMain; private void ChildFRM_Load(object sender, EventArgs e)
{
frmMain = new DataImpMainFRM();
//可以像如下这样操作吗?想做到的效果是,关闭子窗口后,主窗口的数组依然有值。
frmMain.arlOrignal.add("aaa");
frmMain.arlTblDBsvr.add("bbb");
frmMain.arlTblDBName.add("ccc");
frmMain.arlTblDBUser.add("ddd");
frmMain.arlTblDBPsw.add("eee");
}
}
}到底应该怎样做呢?是否一定要做成MDI窗口才行?
主窗体:
namespace DataImport
{
public partial class MainFRM : Form
{
public ArrayList arlOrignal = new ArrayList();
public ArrayList arlTblDBsvr = new ArrayList();
public ArrayList arlTblDBName = new ArrayList();
public ArrayList arlTblDBUser = new ArrayList();
public ArrayList arlTblDBPsw = new ArrayList();
private void butTest_Click(object sender, EventArgs e)
{
DataImpDetailFRM frmChild = new DataImpDetailFRM();
frmChild.Show();
}
}子窗体:
namespace DataImport
{
public partial class ChildFRM : Form
{
private MainFRM frmMain; private void ChildFRM_Load(object sender, EventArgs e)
{
frmMain = new DataImpMainFRM();
//可以像如下这样操作吗?想做到的效果是,关闭子窗口后,主窗口的数组依然有值。
frmMain.arlOrignal.add("aaa");
frmMain.arlTblDBsvr.add("bbb");
frmMain.arlTblDBName.add("ccc");
frmMain.arlTblDBUser.add("ddd");
frmMain.arlTblDBPsw.add("eee");
}
}
}到底应该怎样做呢?是否一定要做成MDI窗口才行?
这句话应该报错吧? public partial class Form1 : Form
{
public int haha = 0;
Form2 frm;
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{ } private void button1_Click(object sender, EventArgs e)
{
frm = new Form2();
frm.Show(this);
} private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show(haha.ToString());
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
((Form1)this.Owner).haha = 2;
}
}
两个FORM,第一个FORM1为启动FORM,其中有两个BUTTON,BUTTON1是打开FORM2,BUTTON2是用MESSAGEBOX显示HAHA的值。
第二个FORM2为子FORM,其中有一个BUTTON1,是用来修改FORM1中HAHA的值。关键是这两句:
frm.Show(this);
和
((Form1)this.Owner).haha = 2;
frmModify frmModify = new frmModify(ip, wellname, tablename, columnname, id, count, dgvData, clboxParameter, cboxFilter, cmbboxFilter, txtboxMin, txtboxMax, cboxSort, cmbboxSort, rbtnAsc, rbtnDesc);
frmModify.ShowDialog();
子窗体:
public partial class frmModify : Form
{
public frmModify(string ipadd, string well, string table, string col, string[] idextent, int cnt, DataGridView dgv, CheckedListBox par, CheckBox cf, ComboBox cbf, TextBox min, TextBox max, CheckBox cs, ComboBox cbs, RadioButton asc, RadioButton desc)
{
InitializeComponent(); //初始化控件
txtboxBaseValue.Clear();
txtboxOffset.Clear(); //接收传递参数
ip = ipadd;
wellname = well;
tablename = table;
columnname = col;
id = idextent;
count = cnt;
dgvData = dgv;
clboxParameter = par;
cboxFilter = cf;
cmbboxFilter = cbf;
txtboxMin = min;
txtboxMax = max;
cboxSort = cs;
cmbboxSort = cbs;
rbtnAsc = asc;
rbtnDesc = desc;
} public string ip; //数据库服务器IP
public string wellname; //井名
public string tablename; //数据表表名
public string columnname; //数据列名
public string[] id; //对应ID号
public int count; //选中的单元格数 //frmMain控件
public DataGridView dgvData;
public CheckedListBox clboxParameter;
public CheckBox cboxFilter;
public ComboBox cmbboxFilter;
public TextBox txtboxMin;
public TextBox txtboxMax;
public CheckBox cboxSort;
public ComboBox cmbboxSort;
public RadioButton rbtnAsc;
public RadioButton rbtnDesc;
{
// 定义你要存储的
public static ArrayList arlOrignal ;
public static ArrayList arlTblDBsvr ;
public static ArrayList arlTblDBName
public static ArrayList arlTblDBUser;
public static ArrayList arlTblDBPsw ;
} private void ChildFRM_Load(object sender, EventArgs e)
{
CStatic.arlOrignal.add("aaa");
CStatic.arlTblDBsvr.add("bbb");
CStatic.arlTblDBName.add("ccc");
CStatic.arlTblDBUser.add("ddd");
CStatic.arlTblDBPsw.add("eee");
}
public partial class Form1 : Form
{
public static int haha;
}public partial class Form2 : Form
{
private void button1_Click(object sender, EventArgs e)
{
Form1.haha=2;
}
}
可以这样实现,不过并不建议这样使用.
{
public ArrayList arlOrignal = new ArrayList();
public ArrayList arlTblDBsvr = new ArrayList();
public ArrayList arlTblDBName = new ArrayList();
public ArrayList arlTblDBUser = new ArrayList();
public ArrayList arlTblDBPsw = new ArrayList();
}
public partial class MainFRM :FormNew
public partial class ChildFRM :FormNew
frmChild.Show();
public partial class ChildFRM : Form
{
private MainFRM frmMain;
//子窗体的构造函数
public ChildFRM (MainFRM main){
frmMain=main;}......
这是最简单的
http://blog.csdn.net/zhzuo/archive/2004/04/05/22027.aspx
http://blog.csdn.net/zhzuo/archive/2006/05/05/708941.aspx
http://blog.csdn.net/zhzuo/archive/2006/05/05/708941.aspx