C# - Toggle button with image, no text - need help, please!!!!

Hi guys,
I want to have a toggle button on my form. I already knew about the way to use a ChechBox or a RadioButton with the Appearance as a Button, but the problem is that I want my toggle button to display an image and there is no text on it.
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
Here is a check box, with Appearance set to Button, which doesn't have the tiny square:

      // checkBox1
      this.checkBox1.Appearance = System.Windows.Forms.Appearance.Button;
      this.checkBox1.Location = new System.Drawing.Point(40, 44);
      this.checkBox1.Name = "checkBox1";
      this.checkBox1.Size = new System.Drawing.Size(44, 36);
      this.checkBox1.TabIndex = 0;

Hi nhagiaubungbu,
you could simulate it using a simple button:
- at first, assign an image to it.
then on teh onclick event, change the image to something else according to a condition.
something like:
if clicked = 1 then load image1
else load image2
clicked:=(clicked+1) % 2;

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Or you could make your own button type deriving from Button. Then override OnClick wher you can change the image according to an internal state variable you define.
Something like this could work:

public class MyButton : Button
      private bool _toggle = false;
      private Image _img1;
      private Image _img2;

      protected override void OnClick(EventArgs e)
            _toggle = !_toggle;
            this.Image = _toggle ? img1 : img2;

      public Image Img1
            get { return _img1; }
            set { _img1 = value; }

      public Image Img2
            get { return _img2; }
            set { _img2 = value; }
Bob LearnedCommented:
I fail to see what's wrong with a CheckBox?

nhagiaubungbuAuthor Commented:
I don't want any text appearing on my button, in that case, a checkbox having appearance as a button will not be shown (it is shown as a tiny square in designer)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.