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 6173815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:38:26+00:00 2026-05-23T23:38:26+00:00

I want to minimize the amount of code i have to write for this

  • 0

I want to minimize the amount of code i have to write for this small problem. I have 1 textbox that has a relationship with 2 checkboxes as yes and no. The textbox on form load is set to disabled. When the yes checkbox is changed this event occurs –

private void checkYes1_CheckedChanged(object sender, EventArgs e)
{
    textBox14.Enabled = true;
    checkNo1_cbx.Checked = false;
}

and when the no checkbox is changed –

private void checkNo1_cbx_CheckedChanged(object sender, EventArgs e)
{
    textBox14.Enabled = false;
    checkYes1_cbx.Checked = false;
}

Although another problem is that i have to press yes twice to get it to check.

This is for a question on a form and so far it goes up to 11 questions and more will be added in the future. So my 2 problems so far is –

  1. How can I fix the problem when the checkbox is changed I have to press it again to check it.

  2. Is it possible to improve this code to minimize the amount of code i will have to write in the future.

  • 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-23T23:38:27+00:00Added an answer on May 23, 2026 at 11:38 pm
    private void checkYes1_CheckedChanged(object sender, EventArgs e)
    {
        OnCheck(true);
    }
    private void checkNo1_cbx_CheckedChanged(object sender, EventArgs e)
    {
        OnCheck(false);
    }
    
    private void OnCheck(bool yes)
    {
        textBox14.Enabled = yes;
        checkNo1_cbx.CheckedChanged -= checkNo1_cbx_CheckedChanged;
        checkNo2_cbx.CheckedChanged -= checkYes1_CheckedChanged;
        checkNo1_cbx.Checked = !yes;
        checkNo2_cbx.Checked = yes;
        checkNo1_cbx.CheckedChanged += checkNo1_cbx_CheckedChanged;
        checkNo2_cbx.CheckedChanged += checkYes1_CheckedChanged;
    }
    

    However consider using RadioBox instead of CheckBox because you want to if one being checked uncheck the other..

    Edit: In your previous design, you get it wrong changed I have to press it again to check it because of you have two event handlers assigned to each of the check boxes. now at your code when the first one checked, you are disable the text box and make the other unchecked, but when you call the other unchecked Checked = false you are calling the second check box event handler also so it will enable the text and make the first one disable… you should remove the event handler by -= when updating at your code if you don’t want the handler handler to be triggered again.. And that what I am doing in the code sample provided.

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

Sidebar

Related Questions

I have a WinForm that I want to minimize when the x in the
i have a window that i want to minimize (to the taskbar), so i
the last thing I want to minimize today is code that contains while and
I have a render-heavy item template in an ItemsControl and want to minimize the
I'm new to CSS and I want to minimize the amount of tagging I
I want to minimize all application that are running in the system, except mine.
We have some code that must access low level windows XP os calls which
I want to minimize javascript in C#. Take for example this javascript I found
Is there a way to Minimize an external application that I don't have control
I'm trying to write code that will traverse an undirected, unweighted graph. Essentially, the

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.