关于子窗体向父窗体取值问题 看这个FAQ:http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=4687 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 textBox1.text = frm.comboBox1.Selectedtext 方法一:在父窗体中定义一个变量,取得comboBox1的值,将此值传进子窗体中。private string strParameter;某个事件中:strParameter=this.comboBox1.SelectedText;在new出子窗体的事件或方法中:ChildForm chfrm=new ChildForm(this.strParameter);在子窗体中:private string strResult;在构造函数中:public ch 设Form1为父窗体,Form2为子窗体;1.把父窗体中的ComboBox设为public;2.在子窗体中加上public Form1 f1;3.在父窗体打开子窗体时这样写:Form2 f2=new Form2();Form2.f1=this;f2.Show();4.在Form2_Load时写:string s=f1.ComboBox.Text;//s即为取到的Form1中的ComboBox的值; public ChildForm(string para){ strResult=para;}这样直接访问strResult就可以取得父窗体的你所要的值了 在构造函数中:public ChildForm(string para){ strResult=para;}这样就可以直接访问strResult来获取comboBox1的text值了。对了这个this.comboBox1.SelectedText;应该改为this.comboBox1.Text; 也可以通过在父窗体中设置一个属性,在子窗体中访问这个属性来获得此值:在MainForm中:public string strParameter{ get { return this.ComboBox1.Text; }}在ChildForm 中:MainForm frm=new MainForm();strResult=frm.strParameter; 91bct(行人)大哥:小弟笨,能把下面的代码再贴出来吗?谢谢 如果斑竹这两句:mainfrm frm = new mainfrm(); textBox1.text = frm.comboBox1.text是在一起的话,无论怎么写都是空的。有几点不明白:1.那个是父窗体呢?是mainfrm还是另一个?2.如果mainfrm是父窗体,为什么在子窗体启动父窗体呢?3.如果mainfrm不是父窗体,第二句话就不应该写在这里。 在子窗口设置一个属性,用来传递参数。例如:子窗口:private string strName1 = "";public string strName{ get { return strName1 } set { strName1 = value; }}在主窗口:frmChild frmChild = new frmChild();frmChild.strName = this.comboBox1.text;frmChild.show();然后在loading子窗体的方法中,为你的textBox 初始化:textBox1.Text = strName1;或者直接把子窗口的textBox设置为public(我认为不是很好啦。)frmChild frmChild = new frmChild();frmChild.textBox1.Text = this.comboBox1.text;frmChild.show(); 新手上路 急急急!!!用JQERY调用C#(ajax),调试时可以执行,发布后却不执行。。。 c#中通过传送的变量值得到某常量的值 txtbox输入内容限制??.NET2003 C# help!!在线等待。 Microsoft 为什么不支持AOP 如何 输出字符串 winform下datagrid双击问题 C# 多文档操作的问题 C#获取局域网内可连接的IP和主机名,在线等。 新手求助! C#+mysql 未指定数据源的问题 c#中关于treeview?????????????? 请问如何在C#中实现管道操作??? 急!!!
在父窗体中定义一个变量,取得comboBox1的值,
将此值传进子窗体中。
private string strParameter;
某个事件中:
strParameter=this.comboBox1.SelectedText;
在new出子窗体的事件或方法中:
ChildForm chfrm=new ChildForm(this.strParameter);
在子窗体中:
private string strResult;
在构造函数中:
public ch
1.把父窗体中的ComboBox设为public;
2.在子窗体中加上public Form1 f1;
3.在父窗体打开子窗体时这样写:
Form2 f2=new Form2();
Form2.f1=this;
f2.Show();
4.在Form2_Load时写:
string s=f1.ComboBox.Text;
//s即为取到的Form1中的ComboBox的值;
{
strResult=para;
}
这样直接访问strResult就可以取得父窗体的你所要的值了
public ChildForm(string para)
{
strResult=para;
}
这样就可以直接访问strResult来获取comboBox1的text值了。
对了这个this.comboBox1.SelectedText;
应该改为this.comboBox1.Text;
在MainForm中:
public string strParameter
{
get
{
return this.ComboBox1.Text;
}
}
在ChildForm 中:
MainForm frm=new MainForm();
strResult=frm.strParameter;
小弟笨,能把下面的代码再贴出来吗?谢谢
mainfrm frm = new mainfrm();
textBox1.text = frm.comboBox1.text
是在一起的话,无论怎么写都是空的。有几点不明白:
1.那个是父窗体呢?是mainfrm还是另一个?
2.如果mainfrm是父窗体,为什么在子窗体启动父窗体呢?
3.如果mainfrm不是父窗体,第二句话就不应该写在这里。
例如:
子窗口:
private string strName1 = "";
public string strName
{
get
{
return strName1
}
set
{
strName1 = value;
}
}
在主窗口:
frmChild frmChild = new frmChild();
frmChild.strName = this.comboBox1.text;
frmChild.show();然后在loading子窗体的方法中,为你的textBox 初始化:textBox1.Text = strName1;
或者直接把子窗口的textBox设置为public(我认为不是很好啦。)
frmChild frmChild = new frmChild();
frmChild.textBox1.Text = this.comboBox1.text;
frmChild.show();