0

So, I'm trying to get a label to reflect the current settings of whatever action is taking place.

this.SettingXLbl.Text = "The current value-set is " + SettingUpDown.Value;

I modified the auto-generated code to attempt to display the current value in the SettingUpDown, but I'm only getting zeroes.

I traded .Value for .Minimum still to get a zero result. The minimum value for the up-down is greater than zero so I'm not sure what I need to do differently to get it to reflect the current value held in the up-down.

Is there some other property that I need to be changing rather than the text itself.

user1993843
  • 155
  • 3
  • 3
  • 13

1 Answers1

3
this.SettingXLbl.Text = "The current value-set is " + SettingUpDown.Value;

You changed that line in the designer's InitializeComponent method. That method is called only once, when the form is constructed. So it will always reflect the value of SettingUpDown.Value at that point in time, which probably was 0 at the time of the form's construction.

You have to explicitly update the label's text in some event. For example, the NumericUpDown control has a ValueChanged event in which you can change the label's text when the value has changed. Simply select the component in the designer, in the Properties window let it display the events, and double click the ValueChanged event. Visual Studio will insert a method stub and associate it with the event. You can fill this stub with any code you want to do your bidding. Something like this:

public void SettingUpDown_ValueChanged(object sender, EventArguments e)
{
    this.SettingXLbl.Text = "The current value-set is " + SettingUpDown.Value;
}
Daniel A.A. Pelsmaeker
  • 47,471
  • 20
  • 111
  • 157
  • Thank you for your explanation! That's exactly what I needed to fix it. For some reason it didn't occur to me to change the label when looking at the Up-down event – user1993843 Apr 02 '13 at 01:46