110,579
社区成员
发帖
与我相关
我的任务
分享
public partial class frmCondition : Form
{
public delegate void dlgOnSelect(string condition);
public event dlgOnSelect OnSelect;
public frmCondition()
{
InitializeComponent();
}
private void btnOk_Click(object sender, EventArgs e)
{
OnSelect("codition1=1;condition2=2;conditon3=3");
this.Close();
}
}
public partial class frmMainSearch : Form
{
public frmMainSearch()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
frmCondition frmCdt = new frmCondition();
frmCdt.OnSelect += new frmCondition.dlgOnSelect(frmCdt_OnSelect);
frmCdt.ShowDialog();
}
private void frmCdt_OnSelect(string condition)
{
MessageBox.Show("选择的条件是:"+condition );
}
}
//Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TestShow
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public Form1(string str)
{
InitializeComponent();
this.label1.Text = str;
}
private void button2_Click(object sender, EventArgs e)
{
Form2 fr2 = new Form2();
fr2.Show();
this.Visible = false;
}
//=========================
//Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace TestShow
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form1 fr1 = new Form1(textBox1.Text);
fr1.Show();
this.Visible = false;
}
}
}
//条件选择
private void btn_search_Click(object sender, EventArgs e)
{
frmCondition frm = new frmCondition();
/*这里不用设置窗体为隐藏,你打开的是模式窗体,在查询窗体“确定”按钮事件中赋值:
this.DialogResult = DialogResult.OK;
这样查询窗体自动会关闭
在查询窗体中定义一个全局属性 ConditionShow ,这样在查询窗体关闭后可以去取值
*/
if (frm.ShowDialog() == DialogResult.OK)
{
this.txt_deptname.Text = frm.ConditionShow;
this.btn_analyze.Enabled = true;
}
}
Form1 结果窗
Form2 查询窗
Form1.cs:
private Form2 f2 = new Form2();
Button1_Click(..)
{
this.Hide();
f2.ShowDialog();
string searchStr = f2.SearchStr;
//...查询
this.Show();
}
Form2.cs:
public string SearchStr="";
Button1_Click(..)
{
//SearchStr="...";
this.Close();
}