我想有一个textbox来修改自定义控件的最大值,发现最大值可以修改,但是控件显示会延后,要等下次点击事件后才能显示出来
比如我修改2,但控件还是显示4下次当我修改为4,控件才把上次赋值的2显示出来每次都是延后一次才会显示.郁闷啊
下面是我的代码
控件名是uivProgressBar1
        private void OnSetValue_Click(object sender, EventArgs e)
        {
            uivProgressBar1.MaxValue = Convert.ToInt32(uiTextBox2.Text);
            uiLabel7.AdsValue = uiTextBox2.Text;
            try
            { 
                NumPadForm dlg = new NumPadForm(
                  ((InjectionMolding.TextBox.UITextBox)sender).AdsVarID,
                  ((InjectionMolding.TextBox.UITextBox)sender).MaxValue,
                  ((InjectionMolding.TextBox.UITextBox)sender).MinValue,
                  ((InjectionMolding.TextBox.UITextBox)sender).Text
                 );
                dlg.ShowDialog();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

解决方案 »

  1.   

    再uiTextBox2加一个TextChanged事件
    private uiTextBox2_TextChanged(object sender,EventArgs e)
    {
      OnSetValue_Click(sender,e); //
    }
      

  2.   

    是这样吗?
    在designer.cs增加
    this.uiTextBox2.Click += new System.EventHandler(this.OnSetValue_Click);(原有)
    this.uiTextBox2.TextChanged +=new System.EventHandler(uiTextBox2_TextChanged);在程序增加
    private void uiTextBox2_TextChanged(object sender, EventArgs e)
     {
      OnSetValue_Click(sender,e);
     }这样都控件的值可以修改成功了,但键盘总是弹几次出来,我再看看
      

  3.   

      dlg.ShowDialog();前加一个判断if(!(sender is uiTextBox))
       dlg.ShowDialog();
      

  4.   

    private void uiTextBox2_TextChanged(object sender, EventArgs e)
     {
      //这里设置最大值
     }