❔ Damn buttons.

I want a button on a WinForm to change varibles to whatever the combobox has selected when the button is clicked. Is this the right format for this?
private void btn_Apply_Click(object sender, EventArgs e)
{

TimeSelector.HourSelector = cb_sdHour.SelectedItem.ToString();
TimeSelector.MinuteSelector = cb_sdMinute.SelectedItem.ToString();
TimeSelector.AmPmBuffer = cb_sdAmPm.SelectedItem.ToString();
lbl_shutdown.Refresh();
}
private void btn_Apply_Click(object sender, EventArgs e)
{

TimeSelector.HourSelector = cb_sdHour.SelectedItem.ToString();
TimeSelector.MinuteSelector = cb_sdMinute.SelectedItem.ToString();
TimeSelector.AmPmBuffer = cb_sdAmPm.SelectedItem.ToString();
lbl_shutdown.Refresh();
}
Basically change the three variables, then refresh the label showing those variables?
15 Replies
necrosisbyte
necrosisbyteOP2y ago
Every other part of the code has been tested and works as it should.
goooosee
goooosee2y ago
@Necro so applying variables doesnt work right?
necrosisbyte
necrosisbyteOP2y ago
Okay so I got that to work, my problem has changed. So I now have to click the button twice for the change to take effect. In debug when I step through it happens on the first click, but when I just ctrl f5 it, it takes two clicks.
private void btn_Apply_Click(object sender, EventArgs e)
{
new TimeSelector(cb_sdHour.SelectedItem.ToString(), cb_sdMinute.SelectedItem.ToString(), cb_sdAmPm.SelectedItem.ToString());
lbl_shutdownHour.Text = (Displays.HDisplay + ":" + Displays.MDisplay + Displays.DAmPm);
}
private void btn_Apply_Click(object sender, EventArgs e)
{
new TimeSelector(cb_sdHour.SelectedItem.ToString(), cb_sdMinute.SelectedItem.ToString(), cb_sdAmPm.SelectedItem.ToString());
lbl_shutdownHour.Text = (Displays.HDisplay + ":" + Displays.MDisplay + Displays.DAmPm);
}
goooosee
goooosee2y ago
could you send more code?
necrosisbyte
necrosisbyteOP2y ago
Sure one sec.
necrosisbyte
necrosisbyteOP2y ago
BlazeBin - gnuwjeyrqxgi
A tool for sharing your source code with the world!
necrosisbyte
necrosisbyteOP2y ago
That's the project in whole, it's pretty small. So when I click apply the text up top should change to whatever the combo boxes are set to, and they do, but I have to click apply twice for it to happen. I think I got it. I have to call the Displays with the button click and not rely on the timer refresh.
goooosee
goooosee2y ago
Well Idk why it doesnt work but i would recommend you creating a new class and add to this public timespan hours { get; set; } And minutes and seconds In your class where you code the buttons import it using MyClass _myClass And use OnPropertyChanged() You gotta make a observableobject class Just copy from the Google its always the same
Ryada
Ryada2y ago
@Necro you are not setting the values in the Display class but in the TimeSelector upon clicking the button Then you set the label to a concatenated string which you build from the values in your Display class So because you never changed the values within Display it won’t show you the correct new time OnPropertychanged isn’t useful for winforms.
SG97
SG972y ago
you mean ObservableObject from the MVVM Community Toolkit? i've never heard of this in WinForms, that's why I'm asking
goooosee
goooosee2y ago
Nope onpropertychanged func
HimmDawg
HimmDawg2y ago
OnPropertychanged isn’t useful for winforms.
This. While it might work, setting up bindings in WinForms is a big pain
goooosee
goooosee2y ago
xd
necrosisbyte
necrosisbyteOP2y ago
@Ryada *ngIf="exists" Thank you that worked. I needed to rebuild the display class to update the values to equal the new TimeSelector values.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server