请问MDI子窗体如何传值给主窗体
目前在 MDI主窗体Form1内 设置了 get 和 set 属性访问器 子窗体FrmLogin是通过菜单控件show出来的FrmLogin frm = new FrmLogin();
frm.MdiParent = this;
frm.show();
现在的问题是我子窗体FrmLogin通过验证后有两个值要传给主窗体Form1 该如何写! 谢谢!!
目前我在窗体是这样写的
。。 //验证用户的代码
Form1 f = new Form1;
f.Quanxian = Covert.ToInt32(quanxian);
f.gonghao = Covert.ToInt32(gonghao);
这样传过去 那里拿不到! 是不是因为我new了一个新的form1的原因? 谢谢!!!!!
--------------------编程问答-------------------- Form1 f = new Form1;
f.Quanxian = Covert.ToInt32(quanxian);
f.gonghao = Covert.ToInt32(gonghao);
quanxian和gonghao是什么东西 --------------------编程问答-------------------- 是两个标志变量! 用来判断权限 和 显示工号的!!
这个两个变量是通过用户登入后 得到的信息 我前面忘记写 this. 了!!! --------------------编程问答--------------------
((Form1)frm.MdiParent).Quanxian--------------------编程问答--------------------
((Form1)f.MdiParent).Quanxian = Covert.ToInt32(quanxian);--------------------编程问答-------------------- new当然拿不到了,因为是另一个对象
((Form1)f.MdiParent).gonghao = Covert.ToInt32(gonghao);
直接从FrmLogin 的MdiParent里面拿就可以了 --------------------编程问答-------------------- 简单一点的话。。。你可以在子窗体里多做一个构造函数。。。
传个主窗体进去就好了~~
private FormFather MyForm;
public FormChild (FormFather f)
{
InitializeComponent();
MyForm = f;
}
--------------------编程问答--------------------
--------------------编程问答-------------------- 在子窗体中在做一个带参的构造函数
Form1 f = new Form1;
f.Quanxian = Covert.ToInt32(quanxian);
f.gonghao = Covert.ToInt32(gonghao); 这段该如何写?
另外
((Form1)f.MdiParent).Quanxian = Covert.ToInt32(quanxian);
((Form1)f.MdiParent).gonghao = Covert.ToInt32(gonghao); 这两个方法 报错说我 未将对象引用??
--------------------编程问答-------------------- class form2
{
private string m_Para = "";
public string Para
{
get
{
return m_Para;
}
}
...
}
------------------------------
form2 f = new form2();
if(f.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = f.Para;
} --------------------编程问答-------------------- 请问 ((Form1)f.MdiParent).Quanxian = Covert.ToInt32(quanxian);
((Form1)f.MdiParent).gonghao = Covert.ToInt32(gonghao); 这个也是要 new 对象的 , 是什么原理 , 能解释一下吗? 谢谢!! --------------------编程问答-------------------- 这个不new对象..只是f.MdiParent已经指向了本来的Form1 --------------------编程问答--------------------
我一般用这个 --------------------编程问答-------------------- 那 ((Form1)f.MdiParent).Quanxian = Covert.ToInt32(quanxian);
这里的 f 是 什么东西啊??? --------------------编程问答--------------------
你还问f是什么意思? --------------------编程问答-------------------- sorry,看错了
应该是
((Form1)this.MdiParent).Quanxian = Covert.ToInt32(quanxian); --------------------编程问答-------------------- 哈哈!! 没问题了!! 请问((Form1)this.MdiParent) 这样写就代表Form1.Quanxian = Covert.ToInt32(quanxian); 不需要new 一个 新的form1 对吗?
(Form1) 这个个引用的意思吗?? 能给我解释一下吗? 效果是达到了 但是没有搞明白里面的意思! 麻烦你了!! --------------------编程问答-------------------- 1.在new Form 时候 用构造函数
2.用CallContext
补充:.NET技术 , C#