A: 

in Form.Loaded handler set groupBox2.Enabled = Properties.Settings.Default.userproxy;

Trickster
+2  A: 

I usually like to do two things differently compared to your code sample:

  • Instead of creating a coupled dependency between controls, create a value describing the state instead
  • Collect code that alters the UI state of controls (such as 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.

Fredrik Mörk
your code can be optimized a little by the way... set { if (_useProxy != value) { _useProxy = value; SetControlStates(); } }is all that's required for the setter for UseProxy :)
mrnye