简体   繁体   中英

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

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM