how to access up down buttons in a NumericUpDown

  • Thread starter Thread starter Bamse
  • Start date Start date
B

Bamse

Hi,
Is there a way (.NET, P/Invoke) to access individual buttons in a
NumericUpDown and DomainUpDown controls?

I need to disable/enable each one of them separately
if the .Value is smaller than myMinValue, the upper button is disabled;
if the .Value is bigger than myMaxValue, the lower button is disabled and
the other one is enabled;

Thank you,
Daniel
 
No easy way. The buttons are painted by the framework and the code for it
resides
in an internal class inside UpDownBase

UpDownBase (the base class for both NumericUpDown and DomainUpDown)
has two childs in its control collection. The first (index 0) is the control
that
paints the buttons. Add an event handler for the Paint event to that control
and draw the buttons yourself. You'll also have to prevent the button click
event from reaching its target if the button is disabled. Overriding
UpButton
and DownButton should do the trick.

BTW, here is the paint code from the framework (C#)
protected override void OnPaint(PaintEventArgs e)
{
int num1;
Size size1;
size1 = base.ClientSize;
num1 = (size1.Height / 2);
ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(0, 0, 16, num1),
0, ((this.pushed == 1) ? 512 : 0));
ControlPaint.DrawScrollButton(e.Graphics, new Rectangle(0, num1, 16,
num1), 1, ((this.pushed == 2) ? 512 : 0));
base.OnPaint(e);
}

Use the same coordinates when drawing your disabled button.

/claes
 
Back
Top