Hi, I am trying to disable a button until a condition is met in my program.

I have two numeric up down boxes and a button, but I want to have the button disabled until the two numeric up down boxes have a number higher than 0 in both of them.

Grateful for any help.

Thanks.

you could use the valueChanged event of the controls to check what the value in each one is?

Something like

btn.visible = false;
decimal upDnVal1 = UpDn1.Value;
decimal upDnVal2 = UpDn2.Value;

private void UpDn1_ValueChanged(object sender, EventArgs e)
{   
   if(upDnVal1 > 0 && upDnVal2 > 0){
   btn.visible = true;
}

and then have the same check for the event for the other up down control.

hope that helps.

Hi, I am trying to disable a button until a condition is met in my program.

I have two numeric up down boxes and a button, but I want to have the button disabled until the two numeric up down boxes have a number higher than 0 in both of them.

Grateful for any help.

Thanks.

This should do the trick:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            DisablingButton();
        }

        private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        {
            DisablingButton();
        }

        private void DisablingButton()
        {
            decimal value1 = numericUpDown1.Value;
            decimal value2 = numericUpDown2.Value;
            if (value1 > 0 && value2 > 0)
                button1.Enabled = false;
            else
                button1.Enabled = true;
        }
    }

Hope it helps,
Mitja

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.