How can I change the forecolor / backcolor of a disabled numeric updown?

StackOverflow https://stackoverflow.com/questions/9790776

  •  25-05-2021
  •  | 
  •  

سؤال

When I disabled Numeric UpDown control I want that user can still read its value. But I can't change Forecolor or Backcolor of that tool. I try to use ReadOnly property instead of Enabled/Disabled property but it doesn't worked either. How can I solve this problem?

هل كانت مفيدة؟

المحلول

I just tried via VS2005 and simple WinForms. I put in the EnableChanged event

private void numericUpDown1_EnabledChanged(object sender, EventArgs e)
{
   NumericUpDown nud = (NumericUpDown)sender;
   nud.BackColor = nud.Enabled ? Color.Yellow : Color.Red;
}

and added another button to the form to just swap its enabled state

private void button2_Click(object sender, EventArgs e)
{
   this.numericUpDown1.Enabled = ! this.numericUpDown1.Enabled;
}

If you create your own NumericUpDown class derived from the base NumericUpDown class and put it within the that, it will do for all instances of YOUR class used in your app without explicitly doing this color changing in every form.

نصائح أخرى

There is no way to achieve this goal with the frame work control. You can use custom draw to implement it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top