pikk
pikk

Reputation: 525

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?

Upvotes: 2

Views: 1050

Answers (2)

DRapp
DRapp

Reputation: 48139

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.

Upvotes: 1

Viacheslav Smityukh
Viacheslav Smityukh

Reputation: 5833

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

Upvotes: 0

Related Questions