日期:2014-05-17  浏览次数:20862 次

c#怎么满足多个事件
如题,本人刚学c#,我想在2件事件同时满足或者说是触发时,才执行某条语句,
例如
[code=C#][/code] private void UserName_TextChanged(object sender, TextChangedEventArgs e)
  {
   
  }

  private void Password_PasswordChanged(object sender, RoutedEventArgs e)
{
 button1.IsEnabled = true;

}
同时满足上面2个事件,设置按钮为可用


------解决方案--------------------
你看 给个bool 值 能满足要求不?
public partial class Form1 : Form
{
bool one = false, two = false;
public Form1()
{
InitializeComponent();
}

private void textBox1_TextChanged(object sender, EventArgs e)
{
//if() 这里可以给个条件如果满足了 才one = true;
one = true;
if ((one == true) && (two == true)) button1.Enabled = true;

}

private void textBox2_TextChanged(object sender, EventArgs e)
{
two = true;
if ((one == true) && (two == true)) button1.Enabled = true;
}
}
------解决方案--------------------
探讨

你看 给个bool 值 能满足要求不?
public partial class Form1 : Form
{
bool one = false, two = false;
public Form1()
{
InitializeComponent();
}

……