Reputation: 816
Well after a long search on web and downloading few projects I landed here for an overall easy to use and small code to implement a toggle button on c# winform project.
I want to have my button to be toggled i.e. two different image possibly with two different text, even I can make the images to have text on it.
Any quick suggestion?
Upvotes: 0
Views: 3184
Reputation: 54433
The usual way is to use a CheckBox
with Appearance=Button
.
You can toggle its ImageIndex
and Text
in the CheckedChanged
event.
You need to associate it with a well-prepared ImageList
of the right ImageSize
an ColorDepth
.
You can get away with ca 3 lines of code:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{ checkBox1.ImageIndex = 1; checkBox1.Text = "Sue"; }
else
{ checkBox1.ImageIndex = 2; checkBox1.Text = "Ellen"; }
}
Upvotes: 2