1、SelectMaterial selFrm=new SelectMaterial();
selFrm.ShowDialog();
转载于贝贝和新浪博客:blog.sina.com.cn/s/blog_6d86f7550100v2sh.html
场景描述:主窗体From1,在主窗体中有一button和TextBox,如下图主窗体
窗体二frmChild有一Button和Textbox2
主窗体中代码:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnOpen_Click(object sender, EventArgs e)
{//点击弹出方法
FrmChild frmChild = new FrmChild();
frmChild.ShowDialog();
if (frmChild.DialogResult == System.Windows.Forms.DialogResult.OK)
{
textBox1.Text = frmChild.StrValue;//获取弹出窗体的属性值
}
}
}
弹出窗口中代码:
public partial class FrmChild : Form
{
public FrmChild()
{
InitializeComponent();
}
private string strValue = "";
public string StrValue
{
get { return strValue; }
set { strValue = value; }
}
private void btnOK_Click(object sender, EventArgs e)
{ //点击确定后
strValue = textBox1.Text; //将文本框的值赋予窗体的属性
this.DialogResult = DialogResult.OK;
this.Close();
}
}