主窗口form1有 控件textBox_path.Text 里存放着一个txt文件的路径
下面是 另一个窗口的代码
private void btnOK_Click(object sender, EventArgs e)//确定按钮事件
{
string path = ff.textBox_path.Text;//如何把主窗口form1里控件textBox_path.Text路径赋值给path?
string newfile=text_content.Text;
File.WriteAllText(path, newfile);//我想在其之前如何清空path路径下txt文件里的内容??
this.Close();
}
public class OtherForm:Form
{
public string FilePath
{
get
{
return textBox_path.Text;
}
}
}
也可以在父窗体中定义个静态的变量,比如strPath
然后
strPath = textBox_path.Text;
在子窗体中 用的时候 可以 Path= ff.strPath 就可以