DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Toggle Text On Button (Single Thread Application)

10.19.2007
| 4043 views |
  • submit to reddit
        // description of your code here

 public partial class Form1 : Form
    {
        int iBtn = 0;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ++iBtn;

            if (iBtn == 3)
            {
                iBtn = 0;
            }

            switch (iBtn)
            {
                case 0: button1.Text = "default";
                    break;
                case 1: button1.Text = "Love";
                    break;
                case 2: button1.Text = "Hate";
                    break;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            button1.Text = "default";
        }
    }