我现在有两个窗口;一个作为主界面,另一个是一对话框的形式出现;我的目的:想单击对话框那个界面的button按钮时,在主界面中显示相应的信息;问题是:每点击一次,就会出现一个一样的主界面;请问怎么解决????
代码:form1中 private void btnEnterInsetStep_Click(object sender, EventArgs e)
{
this.Close();
Form1 f1 = new Form1();
f1.Show();
int index = f1.dgvRecipeEdit.Columns.Add("C", "");
string headerText = "step" + index.ToString();
f1.dgvRecipeEdit.Columns[index].HeaderText = headerText;
f1.dgvRecipeEdit.Columns[index].SortMode = DataGridViewColumnSortMode.NotSortable;
f1.dgvRecipeEdit.Columns[index].DefaultCellStyle.Font = new Font("宋体", 11F);
f1.dgvRecipeEdit.Columns[index].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
f1.dgvRecipeEdit.Columns[index].Width = 130;
}
form2中:
private void btnInsertRecipeStep_Click(object sender, EventArgs e)
{
FormInsertStep fis = new FormInsertStep();
fis.ShowDialog();
代码:form1中 private void btnEnterInsetStep_Click(object sender, EventArgs e)
{
this.Close();
Form1 f1 = new Form1();
f1.Show();
int index = f1.dgvRecipeEdit.Columns.Add("C", "");
string headerText = "step" + index.ToString();
f1.dgvRecipeEdit.Columns[index].HeaderText = headerText;
f1.dgvRecipeEdit.Columns[index].SortMode = DataGridViewColumnSortMode.NotSortable;
f1.dgvRecipeEdit.Columns[index].DefaultCellStyle.Font = new Font("宋体", 11F);
f1.dgvRecipeEdit.Columns[index].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
f1.dgvRecipeEdit.Columns[index].Width = 130;
}
form2中:
private void btnInsertRecipeStep_Click(object sender, EventArgs e)
{
FormInsertStep fis = new FormInsertStep();
fis.ShowDialog();
{
this.Close();
Form1 f1 = new Form1();
f1.Show();
int index = f1.dgvRecipeEdit.Columns.Add("C", "");
string headerText = "step" + index.ToString();
f1.dgvRecipeEdit.Columns[index].HeaderText = headerText;
f1.dgvRecipeEdit.Columns[index].SortMode = DataGridViewColumnSortMode.NotSortable;
f1.dgvRecipeEdit.Columns[index].DefaultCellStyle.Font = new Font("宋体", 11F);
f1.dgvRecipeEdit.Columns[index].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
f1.dgvRecipeEdit.Columns[index].Width = 130;
}
form2中:
private void btnInsertRecipeStep_Click(object sender, EventArgs e)
{
FormInsertStep fis = new FormInsertStep();
fis.ShowDialog();在form1,中show form1,那就只能出现form1窗体了
{
this.Close();
Form1 f1 =Form1.GetInstance();
f1.Show();
......................
}
FormInsertStep 窗体中
static FormInsertStep form = null; public static FormInsertStep GetInstance()
{
if (form == null || form.IsDisposed)
{
form = new FormInsertStep();
}
return form;
}
{
this.Close();
Form1 f1 =Form1.GetInstance();
f1.Show();
......................
}
Form1 窗体中
static Form1 form = null; public static Form1 GetInstance()
{
if (form == null || form.IsDisposed)
{
form = new Form1 ();
}
return form;
}
上面看错了