how to access up down buttons in a NumericUpDown

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
 
C

Claes Bergefall

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top