Click here to Skip to main content
15,891,708 members
Articles / Desktop Programming / Windows Forms
Alternative
Article

Make CheckBox Read Only

Rate me:
Please Sign up or sign in to vote.
1.67/5 (2 votes)
9 Jul 2012CPOL1 min read 45.8K   5   6
This is an alternative for "CheckBoxPanel - A C# CheckBox that auto-enables/disables related controls"

Introduction

CheckBox read only is a simple user control that groups a number of related controls.

Background 

I'm always striving to improve my user interfaces. A common user interface approach is to present an option (for example: "Save to backup file") as a check box, with some additional related settings (e.g., an EditBox containing the filename to write to and a 'browse' button). Most conventional user interfaces either:

  • Leave the settings editable (argh!) when the main option is disabled, or
  • Disable the controls, only enabling them if the main option is first checked.

Let's make things better... When the controls are disabled, why should the user have to click the CheckBox to make them editable? If they click on a child TextBox we can infer that they wish to edit it, which requires the main option to be enabled; so why don't we save them some time and do that for them?  

Using the code 

The article code contains code to make a check box read only.

C#
//
// On Check Changed event 
//
if (checkBox.Checked == true || checkBox.Checked == false)
{
    checkBox.CheckState = CheckState.Checked; 
    checkBox.CheckState = CheckState.Indeterminate;
    //or 
    checkBox.CheckState = CheckState.Checked; 
}

Points of Interest

A good User Interface is all about attention to detail, streamlining user workflows to make it quick and easy to use an application, and adhering to intuitive standards to avoid confusing users. Even tiny features like those provided by the CheckBox can really improve the user experience.  

Automating this type of UI enhancement also saves a lot of programmer time - you have the initial cost of developing a generic solution, but it pays back over the months and years as you find yourself re-using the same code to save time on every application you write.  

History

  • 08-07-2012

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
AnswerThere is a solution: Pin
jcharro197911-Sep-15 2:59
jcharro197911-Sep-15 2:59 
QuestionThere is a solution: Pin
jcharro197911-Sep-15 2:56
jcharro197911-Sep-15 2:56 
GeneralMy vote of 1 Pin
Florian Rosmann1-Oct-13 6:34
Florian Rosmann1-Oct-13 6:34 
GeneralMy vote of 2 Pin
Hekmat906-Apr-13 18:27
Hekmat906-Apr-13 18:27 
GeneralAutocheck Property Pin
John R Hodgson16-Jul-12 13:43
John R Hodgson16-Jul-12 13:43 
QuestionCode? Pin
James Hurburgh10-Jul-12 15:08
James Hurburgh10-Jul-12 15:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.