Fix crash on startup: call OnLimitChanged after _chkScale is initialized
The manual OnLimitChanged(null, EventArgs.Empty) call in the constructor was placed before _chkScale was created, causing a NullReferenceException because the handler reads _chkScale.Checked. Moved the call to after both _limitBar and _chkScale are created and wired.
This commit is contained in:
+1
-1
@@ -182,7 +182,6 @@ public class MainForm : Form
|
||||
Value = 30
|
||||
};
|
||||
_limitBar.ValueChanged += OnLimitChanged;
|
||||
OnLimitChanged(null, EventArgs.Empty);
|
||||
_chkScale = new CheckBox
|
||||
{
|
||||
Text = "Scale",
|
||||
@@ -191,6 +190,7 @@ public class MainForm : Form
|
||||
Checked = false
|
||||
};
|
||||
_chkScale.CheckedChanged += OnLimitChanged;
|
||||
OnLimitChanged(null, EventArgs.Empty);
|
||||
|
||||
Controls.AddRange(new Control[] { _lblBle, _lblWs, _lblStrength, _lblDeviceName, _txtDeviceName, _btnConnect, _btnTest, _btnMusic, _btnStop, _lblTrack, _lblGaugeA, _gaugeA, _lblGaugeB, _gaugeB, _lblLimit, _limitBar, _chkScale });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user