mercredi 23 mars 2016

C# All Check-box Appearance

In my WinForms Visual Studio application i have a checkbox styled as a Flat Button with this C# code:

 private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (TestBox.Checked == true)
        {
            TestBox.Image = Image.FromFile("M:\\CheckBox_52x.png");
            TestBox.ImageAlign = ContentAlignment.MiddleCenter;
            TestBox.FlatAppearance.BorderSize = 0;
            // make all four (!) BackColors transparent!
            TestBox.BackColor = System.Drawing.Color.Transparent;
            TestBox.FlatAppearance.CheckedBackColor = Color.Transparent;
            TestBox.FlatAppearance.MouseDownBackColor = Color.Transparent;

        }
        else
        {
            TestBox.Image = Image.FromFile("M:\\CheckBoxUncheck_52x.png");
            TestBox.ImageAlign = ContentAlignment.MiddleCenter;
            TestBox.FlatAppearance.BorderSize = 0;
            // make all four (!) BackColors transparent!
            TestBox.BackColor = System.Drawing.Color.Cyan;
            TestBox.FlatAppearance.CheckedBackColor = Color.Cyan;
            TestBox.FlatAppearance.MouseDownBackColor = Color.Cyan;
        }
    }

I was wondering, if instead of doing this to every single checkbox in my application, can i apply the "UNCHECKED" version of the checkbox to every single one all at once without having to redo this piece of code over and over, same goes for the checked?

Please keep in mind that i am brand new to coding in C#.




Aucun commentaire:

Enregistrer un commentaire