wpf 自定义控件 的问题 点了按钮以后 反应非常慢 请大神帮助
控件完成的就是一个输入框,右边带上下两个小按钮,可以点按钮以后输入框里的值可以增加会减小,但是实际运行时点那个按钮后会反应很慢,很长时间后数字才会变化后台代码public...
控件完成的就是 一个输入框,右边带上下两个小按钮,可以点按钮以后 输入框里的值可以增加会减小,但是实际运行时 点那个按钮后 会反应很慢,很长时间后 数字才会变化
后台代码
public int Value = 0; private void btnUp_Click(object sender, RoutedEventArgs e) {
if (Value + 1 > Maximum) return; Value++; textBox1.TextChanged -= new TextChangedEventHandler(textBox1_TextChanged); textBox1.Text = Value.ToString(); textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); }
private void btnDown_Click(object sender, RoutedEventArgs e) { if (Value - 1 < Minimum) return; Value--; textBox1.TextChanged -= new TextChangedEventHandler(textBox1_TextChanged); textBox1.Text = Value.ToString(); textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { try { int a = Convert.ToInt32(textBox1.Text); if (a > Maximum) a = Maximum; if (a < Minimum) a = Minimum; Value = a; //textBox1.Text = a.ToString(); } catch { textBox1.Text = Value.ToString(); } } } 展开
后台代码
public int Value = 0; private void btnUp_Click(object sender, RoutedEventArgs e) {
if (Value + 1 > Maximum) return; Value++; textBox1.TextChanged -= new TextChangedEventHandler(textBox1_TextChanged); textBox1.Text = Value.ToString(); textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); }
private void btnDown_Click(object sender, RoutedEventArgs e) { if (Value - 1 < Minimum) return; Value--; textBox1.TextChanged -= new TextChangedEventHandler(textBox1_TextChanged); textBox1.Text = Value.ToString(); textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); }
private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { try { int a = Convert.ToInt32(textBox1.Text); if (a > Maximum) a = Maximum; if (a < Minimum) a = Minimum; Value = a; //textBox1.Text = a.ToString(); } catch { textBox1.Text = Value.ToString(); } } } 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询