Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to swap arrow buttons functionality on NumericUpDown control?

I want to swap the Up and Down arrows (functionality only, not the actual arrows) on NumericUpDown control. For example on clicking the UP arrow the value should decrease and similarly on clicking the Down arrow the value should increase.

I tried to inherit from NumericUpDown class and override UpButton() and DownButton(). I thought that simply swapping the code in between these two methods should work. But upon pasting the DownButton() code into overridden UpButton(),

public class MyCustomNumericUpDown : NumericUpDown
{
    public override void UpButton()
    {
        SetNextAcceleration();
        if (base.UserEdit)
        {
            ParseEditText();
        }

        decimal num = currentValue;
        try
        {
            num -= Increment;
            if (num < minimum)
            {
                num = minimum;
                if (Spinning)
                {
                    StopAcceleration();
                }
            }
        }
        catch (OverflowException)
        {
            num = minimum;
        }

        Value = num;
    }
}

the above program throws the following errors.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The name 'SetNextAcceleration' does not exist in the current context
The name 'currentValue' does not exist in the current context
The name 'minimum' does not exist in the current context
The name 'Spinning' does not exist in the current context
The name 'StopAcceleration' does not exist in the current context
The name 'minimum' does not exist in the current context

I see all these methods and variables are set to private in the base class. Which might be throwing these "does not exist" errors.

Anyone know how to do this?
I just want the arrow buttons functionality swapped. For example on clicking the UP arrow the value should decrease and similarly on clicking the Down arrow the value should increase.

>Solution :

You can derive from the NumericUpDown and override UpButton and DownButton methods like this (by calling base.TheOtherMethod to swap the functionality):

public class CrazyNumericUpDown : NumericUpDown
{
    public override void UpButton()
    {
        base.DownButton();
    }
    public override void DownButton()
    {
        base.UpButton();
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading