Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.50/5 (3 votes)
See more:
I have a toolstrip and i want to add a checkbox to it,but Idont know how to do it.
please help me.
Posted
Updated 5-Apr-16 18:39pm

in form load event:
CheckBox cb = new CheckBox();
cb.Text = "test";
cb.CheckStateChanged += (s, ex) => this.Text = cb.CheckState.ToString();
ToolStripControlHost host = new ToolStripControlHost(cb);
toolStrip1.Items.Insert(0,host);

[edit]Inline code changed to Code block: it preserves the formatting- OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
Pablo Aliskevicius 26-Aug-12 3:39am    
My 5!
Also:

cb.BackColor = Color.Transparent; // to show the toolstrip background.
Ravi Bhavnani 13-Sep-21 1:36am    
Brilliant! +5

/ravi
 
Share this answer
 
Don't use a CheckBox for this purpose.
On a ToolStrip you are supposed to use a ToolStripButton which has the same functionality as a CheckBox. Just use its Checked property!
 
Share this answer
 
Comments
DKcorps 8-May-18 7:56am    
How do I make the ToolStripButton have the same look and feel as a checkbox?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900