Never been to DZone Snippets before?

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

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Toggle Text on Button (Using thread timers)

// Works on a seperate thread and changes the color of a button if a significant event happens

void HotShotTick(object obj)
{
if (this.InvokeRequired) { this.Invoke((MethodInvoker)delegate {
this.FillHotshots();
if (this.dsSignificant.HotshotBets.Rows.Count > 0)
{
this.btnHotShotBets.BackColor = Color.Red;
}
else
{
this.btnHotShotBets.BackColor = Color.Green;
}
});
}

Toggle Text on Button (Single thread application)

// 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";
        }
    }

Toggle an element's display

Sometimes you have a content that shouldn't display
by default. You can provide a link to display/hide
that content
<a href='javascript: toggle()'>toggle</a>
<div id='div1' style='display:none'>
Don't display me
</div>

<script>
function toggle(){
	var div1 = document.getElementById('div1')
	if (div1.style.display == 'none') {
		div1.style.display = 'block'
	} else {
		div1.style.display = 'none'
	}
}
</script>
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS