The code:
using System;
using System.Windows.Forms;
namespace DemoApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
groupBox2.Enabled = checkBox1.Checked;
}
private void button1_Click(object sender, EventArgs e)
{
SaveSetings();
}
private void SaveSetings()
{
Properties.Settings.Default.UserName = textBox1.Text;
Properties.Settings.Default.pass = textBox2.Text;
Properties.Settings.Default.userproxy = checkBox1.Checked;
Properties.Settings.Default.proxy = textBox3.Text;
Properties.Settings.Default.proxy_port = textBox4.Text;
Properties.Settings.Default.Save();
}
//private void Form1_Load(object sender, EventArgs e)
//{
// checkBox1.Refresh();
// groupBox2.Enabled = checkBox1.Checked;
//}
}
}
As u can see in the code I have “Use Proxy” checkbox which is when selected should enable groupbox1 or vice versa. The problem is when the form is loading setting from “user.config“even if the check control is unselected groupbox 1 is enabled. One way to handle this situation is to check for the control in form load event i.e.
groupBox2.Enabled = checkBox1.Checked;
is there any other to do this and make my application more dinamic?
The reason I am asking this is because there can be situations where multiple controls are on a single form, and I think it will become confusing.

I usually like to do two things differently compared to your code sample:
VisibleandEnabled) into one single method, and call that whenever needed.Example:
Then, in
Form_Load, when reading from the configuration file, you simply assignthis.UseProxywith 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.