窗体间传值的方法:
如窗体1内的textbox内的内容要在窗体2的label上显示
方法一:
1. 窗体1内的重要代码:
FrM f = new FrM();
f.Show();
窗体2内的重要代码:
登录 d = (登录)Owner;
string a = d.name_textBox.Text;
this.toolStripStatusLabel2.Text = "当前用户: "+a;
在登录窗体内的name_textBox.Text的Modifies属性改为Public;
方法二:使用委托
窗体1:
public delegate void returnValue(DataSetd);
//定义委托事件
public static event returnValue returnValueEvent;
//委托时间的函数
public void doreurnValue(DataSet d)
{
returnValueEvent(d);
}
void FrM_returnValueEvent(DataSet d)
{
this.dataGridView1.Visible = true;
this.dataGridView1.DataSource = d.Tables[0];
}
private void 新建查询ToolStripMenuItem_Click(objectsender, EventArgs e)
{
Search s;
s = new Search();
returnValueEvent+=newreturnValue(FrM_returnValueEvent);
s.Show();
s.MdiParent = this;
this.dataGridView1.Visible = false;
}
窗体2:
private void button1_Click(object sender,EventArgs e)
{
bool a=radioButton1.Checked;
bool b=radioButton2.Checked;
bool c=radioButton3.Checked;
if (a == true)
{
SqlConnection conn = newSqlConnection("server=.;database=Data_Collection;uid=123;pwd=123");
string temper_search ="select * from Data where Temperature between '" + Tem_textBox2.Text+ "'and '" + Tem_textBox1.Text+ "'";
//SqlCommand cmd =newSqlCommand(temper_search, conn);
conn.Open();
SqlDataAdapter sa = newSqlDataAdapter(temper_search, conn);
DataSet ds = new DataSet();
sa.Fill(ds);
FrM cx = new FrM();
cx.doreurnValue(ds);
conn.Close();
}