I want to set binary values on and of at will. So I derived from the CheckBox class to change it's appearance. Instead of a checkmark I like to implement a 0 or 1 here.
This is the code of my class so far:

class BinarycheckBox : CheckBox
    {
        public BinarycheckBox()
        {
          
        }
    }

Nothing special, I expected to get a normal checkbox with the following:

public partial class Form1 : Form
    {
        private BinarycheckBox BinCB;

        public Form1()
        {
            InitializeComponent();

            //initialize new binary checkbox
            this.BinCB = new BinarycheckBox();
           
            this.BinCB.AutoSize = true;
            this.BinCB.Location = new System.Drawing.Point(70, 95);
            this.BinCB.Name = "bin";
            this.BinCB.Size = new System.Drawing.Size(80, 17);
            this.BinCB.TabIndex = 0;
            this.BinCB.Text = "bin";
            this.BinCB.UseVisualStyleBackColor = true;
            this.BinCB.Visible = true; //even this does not work
            
        }
    }

This compiles and runs perfectly, but no checkbox is showing. What am I overlooking here? Any help will be much appreciated.

Recommended Answers

All 3 Replies

Hello, ddanbe. All you have to do is add your BinCB to the list of Controls of your form:

this.Controls.Add(this.BinCB);
commented: I could have known this but thanks for reminding! +4

I knew it must have been something terribly stupid! Thanks for reminding me I am still human. In latin one would say : errare humanum est.
Keep on your good work.

:D you're welcome

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.