WinForm窗体间传值
2010-07-01 16:18
134 查看
Form1——主窗体:
namespace FirstDlg
{
public partial class Form1 : Form
{
private Form2 f;
public Form1()
{
InitializeComponent();
}
public string TextStored
{
get { return tbTest.Text; }
set { tbTest.Text = value; }
}
private void button1_Click(object sender, EventArgs e)
{
tbTest.Text = f.TextStored;//属性传值
}
private void Form1_Load(object sender, EventArgs e)
{
f = new Form2();
f.Show();
}
}
}
Form2——对话框窗体:
namespace FirstDlg
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public string TextStored
{
get { return tbTest.Text; }
set { tbTest.Text = value; }
}
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (Form form in Application.OpenForms)//搜索窗体名称
{
if (form.Name == "Form1")
{
Form1 f = (Form1)form;
tbTest.Text = f.TextStored;
}
}
}
}
}
namespace FirstDlg
{
public partial class Form1 : Form
{
private Form2 f;
public Form1()
{
InitializeComponent();
}
public string TextStored
{
get { return tbTest.Text; }
set { tbTest.Text = value; }
}
private void button1_Click(object sender, EventArgs e)
{
tbTest.Text = f.TextStored;//属性传值
}
private void Form1_Load(object sender, EventArgs e)
{
f = new Form2();
f.Show();
}
}
}
Form2——对话框窗体:
namespace FirstDlg
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
public string TextStored
{
get { return tbTest.Text; }
set { tbTest.Text = value; }
}
private void btnOK_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (Form form in Application.OpenForms)//搜索窗体名称
{
if (form.Name == "Form1")
{
Form1 f = (Form1)form;
tbTest.Text = f.TextStored;
}
}
}
}
}
相关文章推荐
- WinForm窗体之间传值
- (C#)WinForm窗体间传值
- WINFORM中被调用窗体向调用它的窗体传值
- WinForm开发,窗体显示和窗体传值相关知识总结
- C# Winform窗体间传值
- winform 窗体传值 转http://www.cnblogs.com/kivenhou/archive/2010/09/07/1820950.html
- WinForm 模式窗体传值的问题
- winform窗体间传值
- WinForm开发,窗体显示和窗体传值相关知识总结 (转)
- winform 利用属性在父、子窗体间传值
- WinForm中窗体中的页面传值
- Winform窗体间传值
- [导入]Winform间窗体传值
- 在Winform 窗体之间 委托传值
- .C# WinForm 父窗体 子窗体 传值
- Winform窗体间传值
- WinForm窗体间如何传值的几种方法
- Visual Studio 中两个窗体(WinForm)之间相互传值的方法
- winform 窗体间传值
- WinForm中的窗体传值