Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 428197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:39:07+00:00 2026-05-12T19:39:07+00:00

The winform: The code: using System; using System.Windows.Forms; namespace DemoApp { public partial class

  • 0

The winform:
alt text

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:39:07+00:00Added an answer on May 12, 2026 at 7:39 pm

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 224k
  • Answers 224k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'd say it depends on when you expect to get… May 13, 2026 at 12:49 am
  • Editorial Team
    Editorial Team added an answer I suspect you got a call to touchesCancelled:withEvent: in those… May 13, 2026 at 12:49 am
  • Editorial Team
    Editorial Team added an answer I suggest you call @user.changed? like the following example to… May 13, 2026 at 12:49 am

Related Questions

I have created 2 forms in VS Studio 2008 Express Edition and declare them
Follow up to this question: Winforms Style / UI Look and Feel Tips So
In a winforms app, in a form's Load event, add the following line: throw
I'm trying to drag data from the Winforms portion of my application on a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.