0

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.

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by Mitja Bonca
0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.