in Form.Loaded handler set groupBox2.Enabled = Properties.Settings.Default.userproxy;
Trickster
2009-10-25 06:50:00
in Form.Loaded handler set groupBox2.Enabled = Properties.Settings.Default.userproxy;
I usually like to do two things differently compared to your code sample:
Visible
and Enabled
) into one single method, and call that whenever needed.Example:
private bool _useProxy;
private bool UseProxy
{
get
{
return _useProxy;
}
set
{
bool valueChanged = _useProxy != value;
_useProxy = value;
if (valueChanged)
{
SetControlStates();
}
}
}
private void SetControlStates()
{
groupBox2.Enabled = this.UseProxy;
checkBox1.Checked = this.UseProxy;
}
private void checkBox1_CheckedChanged(object sender, EventArgs
this.UseProxy = checkBox1.Checked;
}
Then, in Form_Load
, when reading from the configuration file, you simply assign this.UseProxy
with the value from the file. This way different controls are not dependent in each other in the same way, but rather on the state that they are related to.