怎样在子窗体为父窗体的textbox赋值?父窗体public string strpath = ""; private void btnAddFtpFile_Click(object sender, EventArgs e)
{
string strip=txtFtpServer.Text.Trim().ToString();
string strname=txtFtpUserName.Text.Trim().ToString();
string strpwd=txtFtpPassword.Text.Trim().ToString(); frmFtpFileTree frm = new frmFtpFileTree(strip,strname,strpwd);
frm.ShowDialog(); //打开子窗体 this.txtFtpPath.Text = strpath.ToString();
//等子窗体关闭后,为textbox赋值。 但是子窗体关闭后还是赋值不了。 }
子窗体
private void btnOK_Click(object sender, EventArgs e)
{
frmListFileAdd frm = new frmListFileAdd(); frm.strpath="waetrwe"; //为父窗体的公共变量赋值
//this.Close();
}
帮我看看
{
string strip=txtFtpServer.Text.Trim().ToString();
string strname=txtFtpUserName.Text.Trim().ToString();
string strpwd=txtFtpPassword.Text.Trim().ToString(); frmFtpFileTree frm = new frmFtpFileTree(strip,strname,strpwd);
frm.ShowDialog(); //打开子窗体 this.txtFtpPath.Text = strpath.ToString();
//等子窗体关闭后,为textbox赋值。 但是子窗体关闭后还是赋值不了。 }
子窗体
private void btnOK_Click(object sender, EventArgs e)
{
frmListFileAdd frm = new frmListFileAdd(); frm.strpath="waetrwe"; //为父窗体的公共变量赋值
//this.Close();
}
帮我看看
------------------------------>public static string strpath = "";
private void btnOK_Click(object sender, EventArgs e)
{
frmListFileAdd frm = new frmListFileAdd(); frm.strpath="waetrwe"; //为父窗体的公共变量赋值
//this.Close();
}
------------------------------>private void btnOK_Click(object sender, EventArgs e)
{ frmListFileAdd .strpath="waetrwe";
}
window.document.getElementById("aaa");
找到给赋值就OK了!
private void button1_Click(object sender, EventArgs e)
{
Form2 f = new Form2(this);
f.Show();
}
子窗体
Form1 frm;
public Form2(Form1 fr)
{
frm = fr;
InitializeComponent();
} private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
frm.textBox1.Text = "ddd";//textBox1是父窗体的一个控件, 要设为公有
}
private void btnAddFtpFile_Click(object sender, EventArgs e)
{
string strip=txtFtpServer.Text.Trim().ToString();
string strname=txtFtpUserName.Text.Trim().ToString();
string strpwd=txtFtpPassword.Text.Trim().ToString(); using(frmFtpFileTree frm = new frmFtpFileTree(strip,strname,strpwd))
{
if(frm.ShowDialog()==DialogResult.OK)//打开子窗体
{
this.txtFtpPath.Text = frm.strpath;
}
}
}
子窗体:
public string strpath = "";
private void btnOK_Click(object sender, EventArgs e)
{
this.strpath="waetrwe"; //为父窗体的公共变量赋值
this.DialogResult = DialogResult.OK;
}
你的值赋给了子窗体的变量。直接写strpath="waetrwe" 就赋上了
自己去看下,很详细的。
在子窗体中加一个函数,形式是这样的:private string m_Result = ""; // 返回值
public string ShowMe(这里可以加一些参数)
{
this.ShowDialog();
return m_Result;
}// 在父窗体中就这样调用就行了:
txtControl.Text = frmChild.ShowMe(参数);
{
frmListFileAdd frm = new frmListFileAdd(); frm.txtFtpPath.Text="waetrwe"; //为父窗体的公共变量赋值
this.Close();
}
{
get
{
return this.textBox1.Text;
}
set
{
this.textBox1.Text = value;
}
}
public event EventHandler accept;
private void button1_Click ( object sender , EventArgs e )
{
if ( accept != null )
{
accept ( this , EventArgs.Empty );
}
}
form1:中
Form2 f2 = new Form2 ( );
f2.accept += new EventHandler ( f2_accept );
f2.Show ( );
void f2_accept ( object sender , EventArgs e )
{
Form2 f2 = (Form2) sender;
this.textBox1.Text = f2.Form2Value;
}
这样就可以了..
{
Form2 f2 = new Form2();
f2.ShowDialog(this);
}子窗体 Form2private void button2_Click(object sender, EventArgs e)
{
Form1 f1 = (Form1)this.Owner;
f.textbox1.text = "aaaaaaaaa";
}