tags:

views:

73

answers:

3

I want to set the default property of a checkbox to true

+1  A: 

Set the Checked property to True in the Properties window of Visual Studio at design time.

logicnp
+1  A: 

For a given checkbox? Edit the form in the forms designer, and change the Checked property to true.

For all checkboxes in the environment, without changing each individually? Can't be done. Though I suppose if you got really ambitious, you could write a post-compiler or some such.

Michael Petrotta
+2  A: 

You haven't specified which platform, so I'll answer this for WPF, in which it's definitely possible.

You can use the OverrideMetadata method on CheckBox.IsCheckedProperty to provide a default value of "true" for all CheckBoxes. Add this code to your App class (in App.xaml.cs):

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);

    CheckBox.IsCheckedProperty.OverrideMetadata(typeof(CheckBox),
        new FrameworkPropertyMetadata(true));
}
Matt Hamilton