日期:2014-05-18  浏览次数:20818 次

C# 在A介面显示B介面设置的内容
请教:我建了一个公共变量:
#region Class
public static class GlobalConst
{
  public static string strIfeng = "操作员";
}
#endregion
在A介面显示:当前用户:Lable(name:buttonifeng)
private void FormMain_Load(object sender, EventArgs e)  
 {
  labelifeng.Text = GlobalConst.strIfeng;

  }
  private void FormMain_Load(object sender, EventArgs e)
   
  {
  labelifeng.Text = GlobalConst.strIfeng;

  }
B介面显示:当前用户:Lable(name:buttonifeng)
有三个按钮:操作员、工程师、管理者,我在这个画面切这三个按钮,在当前用户上都可以显示切换,而进入A介面当前用户还是显示“操作员”
请教一下,哪里有问题,(新人)
  private void ifeng_Click(object sender, EventArgs e)
  {
  string strFormText = ((System.Windows.Forms.Button)sender).Name.Trim();

  if (strFormText == "Operator")
  { 
  Operator.Enabled = false;
  Engineer.Enabled = true;
  Master.Enabled = true;
  GlobalConst.strIfeng = "操作员";
  labelifeng.Text = GlobalConst.strIfeng;
  }
   


  if (strFormText == "Engineer")
  {
  Form2 a1=new Form2();

  a1.ShowDialog();
  if (a1.DialogResult == DialogResult.OK)
  {
  Engineer.Enabled = false;
  Operator.Enabled = true;
  Master.Enabled = true;
  GlobalConst.strIfeng = "工程师";
  labelifeng.Text = GlobalConst.strIfeng;
   
  }
   
   
  }
  if (strFormText == "Master")
  {
  Form3 a2 = new Form3();

  a2.ShowDialog();
  if (a2.DialogResult == DialogResult.OK)
  {
  Engineer.Enabled = true;
  Operator.Enabled = true;
  Master.Enabled = false;
  GlobalConst.strIfeng = "管理者";
  labelifeng.Text = GlobalConst.strIfeng;

  }
   
  }

  }

------解决方案--------------------
A的OnLoad只执行一次,你不如在Form1_Activated事件 中写
------解决方案--------------------
GlobalConst.strIfeng 这个值已经变化
但是并没有事件通知 labelifeng.Text 发生变化

在A窗体的获得活动事件写上你的那句话
labelifeng.Text = GlobalConst.strIfeng;