0

I want to build a function for holding a Button in C#. Currently it looks like this:

private Timer timer1 = new Timer();

private void cmd_haken_auf_ab_MouseDown(object sender, MouseEventArgs e)
{
    Console.WriteLine("works");
    timer1.Enabled = true;
    timer1.Start();

}

private void cmd_haken_auf_ab_MouseUp(object sender, MouseEventArgs e)
{
    Console.WriteLine("works too");
    timer1.Stop();
}


private void timer1_Tick(object sender, EventArgs e)
{
    Console.WriteLine("works as well");
    cmd_p4.Height += 1;

}

But appearently my timer1_Tick function is never executed, as the Output is:

works
works too
works
works too
dotNET
  • 33,414
  • 24
  • 162
  • 251

2 Answers2

0

mention timer tick_event for your timer and add timer interval.

timer1.Interval = 1000; timer1.Tick+=timer1_Tick;

Ajay
  • 6,418
  • 18
  • 79
  • 130
0

Add in constructor:

timer1.Tick += new timer1_Tick(TimerEventProcessor);

This should result in call every tick of your timer. If wont work, set interval of timer like

timer1.Interval = 1; // 1ms interval