读书人

c#如何满足多个事件

发布时间: 2012-10-08 19:54:56 作者: rapoo

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();
}

……

读书人网 >C#

热点推荐