不同窗口间的相互作用 本帖最后由 tuyi911 于 2010-10-11 14:27:28 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 F1 窗体:public partial class F1 : Form { public F1() { InitializeComponent(); } //添加事件 private void btnAdd_Click(object sender, EventArgs e) { F2 f = new F2(this); f.Show(); }}F2 窗体:public partial class F2 : Form { Form f = new Form(); public F2(Form form) //构造函数 { f = form; InitializeComponent(); } //确定时间 private void btnConfirm_Click(object sender, EventArgs e) { ((F1)f).listBox1.Items.Add(this.textBox1.Text.Trim()); //1窗体的listbox添加 this.Hide(); f.Show(); ((F1)f).listBox1.Refresh(); } } 窗口传值用委托子窗口调用父窗口控件看我博客http://blog.csdn.net/chazikai24/archive/2010/09/01/5855254.aspx 委托实现Form2 f2 = new Form2(); private void button1_Click(object sender, EventArgs e) { f2.MyA+= new Form2.AA(B); f2.Show(); }void B(string str){}public delegate void AA(string str);public event AA MyA; private void button1_Click(object sender, EventArgs e) { this.MyA(); }父窗体:protected void btnEidt_Click(object sender,EventArgs arg){ if(SubForm().ShowDialog()==DialogResult.Ok) { //再次调用数据绑定代码。 }} Form1 private void button1_Click(object sender, EventArgs e) { using (Form2 frm = new Form2()) { if (frm.ShowDialog() == DialogResult.OK) { listBox1.Items.Add(frm.Content); } } }Form2 public string Content { get { return this.textBox1.Text; } } private void button1_Click(object sender, EventArgs e) { this.DialogResult = DialogResult.OK; } 窗体程序调用WCF,提示:调用方未由服务进行身份验证 c# 向Excel中传数据 IIS下网站与网站下一个虚拟目录如何共享session???? 我想做个想QQ一样的消息提示框! 我是菜鸟,问一个C#很菜的问题! 学习c#给推举基本好书。 winform下有什么好的datagrid控件. 更改Appconfig里的 数据库连接词 在WinForm中,BindingContext起到什么作用? 高手们应该不介意一个简单的问题吧? 新手问题! VS2005C# 开发的EXE易中毒.救命
{
public F1()
{
InitializeComponent();
}
//添加事件
private void btnAdd_Click(object sender, EventArgs e)
{
F2 f = new F2(this);
f.Show();
}
}
F2 窗体:public partial class F2 : Form
{
Form f = new Form();
public F2(Form form) //构造函数
{
f = form;
InitializeComponent();
} //确定时间
private void btnConfirm_Click(object sender, EventArgs e)
{
((F1)f).listBox1.Items.Add(this.textBox1.Text.Trim()); //1窗体的listbox添加
this.Hide();
f.Show();
((F1)f).listBox1.Refresh();
}
}
用委托
子窗口调用父窗口控件
看我博客
http://blog.csdn.net/chazikai24/archive/2010/09/01/5855254.aspx
Form2 f2 = new Form2();
private void button1_Click(object sender, EventArgs e)
{
f2.MyA+= new Form2.AA(B);
f2.Show();
}
void B(string str){}public delegate void AA(string str);
public event AA MyA;
private void button1_Click(object sender, EventArgs e)
{
this.MyA();
}
父窗体:
protected void btnEidt_Click(object sender,EventArgs arg)
{
if(SubForm().ShowDialog()==DialogResult.Ok)
{
//再次调用数据绑定代码。
}
}
{
using (Form2 frm = new Form2())
{
if (frm.ShowDialog() == DialogResult.OK)
{
listBox1.Items.Add(frm.Content);
}
}
}Form2 public string Content
{
get { return this.textBox1.Text; }
} private void button1_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
}