MDI窗体传值的问题 MDI父窗体f1上面有个button.点击button ShowDialog f2子窗体点击f2子窗体上的button,f2关闭的同时把f2的值传到f1上去,怎么办最好有代码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 很多办法比如在父窗体上建一个静态变量,假设你传回的是string类型public static string aaa;在f2的button事件中写f1.aaa = "返回值"; 在f2中:f1 form;在f1的button事件中:f2 ff=new f2();f2.form=this;ff.showdialog(this);f2的button事件中:form.控件名=要传的值;this.close(); 又或者你在子窗体上建一个变量存储返回值public sting aaa;在点击事件中给aaa赋值aaa = "返回值";在父窗体创建子窗体的时候这么写private string aaa;f2 newMDIChild_1 = new f2();newMDIChild_1.MdiParent = this;newMDIChild_1.Show();this.aaa = newMDIChild_1.aaa; f1中增加个属性private string str = string.Empty;public string MyProperty{set{str = value;}get{return str;}}f1的按钮点击事件,f2 ff=new f2();ff.showdialog(this); f2的按钮点击事件中this.Owner.MyProperty = "test";this.Close();属性的类型可以根据自己的需要更换。 申明一个Object对象作为参数传过去,C#中所有Object对象都是引用类型,如你传个button或者DATASET之类的变量过去,在对应的界面定义变量,然后把传过去的对象给他就行了如果全的是值类型,可以定义Public类型,在主界面上直接访问,如果子界面已经关闭,可以考虑写Object类,把你的值类型(string,struct)放在类中,然后传回Object类 我是这样写的f1:public string str = null;private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked == true) { frmCustomerinfo customer = new frmCustomerinfo(); customer.FormClosing += new FormClosingEventHandler(customer_FormClosing); customer.ShowDialog(); } } void customer_FormClosing(object sender, FormClosingEventArgs e) { MessageBox.Show(str); }f2:private void button2_Click(object sender, EventArgs e) { frmInfo info = new frmInfo(); info.str = "员工"; MessageBox.Show(info.str); this.Close(); } 申明一个Object对象作为参数传过去,C#中所有Object对象都是引用类型,如你传个button或者DATASET之类的变量过去,在对应的界面定义变量,然后把传过去的对象给他就行了子界面做任何操作都会修改其中的值 cdsgajxlp能不能详细谈下给点代码看看 服了 改成下面的样子f1: public string str = null; private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked == true) { frmCustomerinfo customer = new frmCustomerinfo(); customer.ShowDialog(); this.str = customer.str; MessageBox.show(str); } } f2: string str;private void button2_Click(object sender, EventArgs e) { str = "员工"; MessageBox.Show(info.str); this.Close(); } MDI父窗体f1上面有个button.点击button ShowDialog f2子窗体 点击f2子窗体上的button,f2关闭的同时把f2的值传到f1上去,怎么办 ----------------------------------------------------------------父窗体:f1 public string aa = string.Empty;//可以是集合 //点击button f2 newF2 = new f2(); f2.Owner = this;//this==f1; f2.Show();子窗体:f2 //code.... ((f1)f2.Owner).aa = "f2_has_changed_itsValue"; this.Close();//this==f2 在f2的窗口中定义一个变量 ---public f1 aaaaa;同时把构造函数改成: public f2(f1 asf1) { InitializeComponent(); aaaaa=asf1; } 在f1 的button按钮中的 f2 bbbb=new f2(this); bbbb。show();这样就ok了。 关于wpf中datagrid动态设置单元格背景问题! 双击txt文档如何用自己的记事本程序打开 .net开发的高手们啊,请教一个问题啊,急的火烧眉毛了!!! 命名空间的父、子、孙之间是否有什么编程、开发等逻辑关系,还是仅仅为了便于分块管理? C#控制键盘按键输入 请教一条数据库语句~~ 爱好C#的程序员朋友,欢迎加入C#.NET交流群 请开发过IC卡系统的大虾指教? 怎样判断一个文件是否是.ASP文件?INDEXOF怎么用? 如何让文本框在输入20020621数字时自动转成2002-06-21的日期格式? ASP.net 与 C#编程:页面间函数调用? 救命,如何实现,多个计时器?
比如在父窗体上建一个静态变量,假设你传回的是string类型
public static string aaa;在f2的button事件中写
f1.aaa = "返回值";
在f1的button事件中:
f2 ff=new f2();
f2.form=this;
ff.showdialog(this);f2的button事件中:
form.控件名=要传的值;
this.close();
public sting aaa;
在点击事件中给aaa赋值
aaa = "返回值";在父窗体创建子窗体的时候这么写
private string aaa;
f2 newMDIChild_1 = new f2();
newMDIChild_1.MdiParent = this;
newMDIChild_1.Show();
this.aaa = newMDIChild_1.aaa;
private string str = string.Empty;
public string MyProperty
{
set
{
str = value;
}
get
{
return str;
}
}f1的按钮点击事件,
f2 ff=new f2();
ff.showdialog(this); f2的按钮点击事件中
this.Owner.MyProperty = "test";
this.Close();属性的类型可以根据自己的需要更换。
f1:
public string str = null;
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
frmCustomerinfo customer = new frmCustomerinfo();
customer.FormClosing += new FormClosingEventHandler(customer_FormClosing);
customer.ShowDialog();
}
} void customer_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show(str);
}f2:
private void button2_Click(object sender, EventArgs e)
{
frmInfo info = new frmInfo();
info.str = "员工";
MessageBox.Show(info.str);
this.Close();
}
子界面做任何操作都会修改其中的值
能不能详细谈下
给点代码看看
f1:
public string str = null;
private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
frmCustomerinfo customer = new frmCustomerinfo();
customer.ShowDialog();
this.str = customer.str;
MessageBox.show(str);
}
}
f2:
string str;
private void button2_Click(object sender, EventArgs e)
{
str = "员工";
MessageBox.Show(info.str);
this.Close();
}
点击f2子窗体上的button,f2关闭的同时把f2的值传到f1上去,怎么办
----------------------------------------------------------------
父窗体:f1 public string aa = string.Empty;//可以是集合
//点击button
f2 newF2 = new f2();
f2.Owner = this;//this==f1;
f2.Show();子窗体:f2
//code....
((f1)f2.Owner).aa = "f2_has_changed_itsValue";
this.Close();//this==f2
---public f1 aaaaa;
同时把构造函数改成:
public f2(f1 asf1)
{
InitializeComponent();
aaaaa=asf1;
}
在f1 的button按钮中的
f2 bbbb=new f2(this);
bbbb。show();这样就ok了。