This is a small program which shows the basic functionality of C#. The program contains 2 labels. The labels are shown to blink alternatively with the help of two timers. Whenever a timer is enabled, the other timer is relaxed and a label linked with the corresponding timer has its visible property set to true while the other label has its visible property set to false. This simple logic gives us the effect of alternative blinking of the labels. You can set the tick property of the timer to a suitable number. This gives the time in milliseconds between the blinks. A word of caution : do not simply copy paste codes written here instead type it in your IDE. For example to type in the code for the first timer timer1 , double click on the timer1 which gives you a fraction of code ready to begin with and then type in the code within the closed block of curly braces.
namespace Hello_World
{
public partial class FrmHelloWorld : Form
{
public FrmHelloWorld()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
lblWorld.visible = false;
lblHello.Visible = true;
timer1.Enabled = false;
timer2.Enabled = true;
}
private void timer2_Tick(object sender, EventArgs e)
{
lblHello.Visible = false;
lblWorld.Visible = true;
timer2.Enabled = false;
timer1.Enabled = true;
}
private void cmdClickHere_Click(object sender, EventArgs e)
{
if (cmdClickHere.Text = "Click Here !")
{
timer1.Enabled = true;
cmdClickHere.Text = "STOP !";
}
else
if (cmdClickHere.Text = "STOP !")
{
timer1.Enabled = false;
timer2.Enabled = false;
cmdClickHere.Text = "Click Here !";
}
}
}
}
Please Note :
** Do not Copy & Paste code written here ; instead type it in your Development Environment
** Testing done in .Net Framework 2.0 but code should be very similar for subsequent versions of .Net
** All Program Codes on Blog are 100% tested & running.
** Do not Copy & Paste code written here ; instead type it in your Development Environment
** Testing done in .Net Framework 2.0 but code should be very similar for subsequent versions of .Net
** All Program Codes on Blog are 100% tested & running.