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:
2026-08-08 10:55:30 +00:00
parent 44421a51e3
commit 4ae5c397fd
+1 -1
View File
@@ -182,7 +182,6 @@ public class MainForm : Form
Value = 30 Value = 30
}; };
_limitBar.ValueChanged += OnLimitChanged; _limitBar.ValueChanged += OnLimitChanged;
OnLimitChanged(null, EventArgs.Empty);
_chkScale = new CheckBox _chkScale = new CheckBox
{ {
Text = "Scale", Text = "Scale",
@@ -191,6 +190,7 @@ public class MainForm : Form
Checked = false Checked = false
}; };
_chkScale.CheckedChanged += OnLimitChanged; _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 }); Controls.AddRange(new Control[] { _lblBle, _lblWs, _lblStrength, _lblDeviceName, _txtDeviceName, _btnConnect, _btnTest, _btnMusic, _btnStop, _lblTrack, _lblGaugeA, _gaugeA, _lblGaugeB, _gaugeB, _lblLimit, _limitBar, _chkScale });