Note that there are some explanatory texts on larger screens.

plurals
  1. POc# winform - using timer to animate drop down menu
    primarykey
    data
    text
    <p>I am trying to make an animated drop down menu in winforms. The form would expand when there is a mouse_enter event and contract back to original size when there is a mouse_leave event. I use a timer to control the rate of "animation" to achieve the desired result.</p> <p>upon running the first few times, the "animation" is according to what i want but after a few loops (mouse in -> mouse out - > mouse in -> mouse out -> etc), the animation starts to speed up until it reaches a point where it would just simply appear/disappear at a fast speed.</p> <p>are there alternatives to achieve this effect or maintain the desired rate of animation?</p> <p>btw, this is my first question here so do advise me if I broke any rules/formats etc!</p> <pre><code> private void setForm() { this.Location = new Point(Screen.GetWorkingArea(this).Width - this.Width, Screen.GetWorkingArea(this).Height - this.Height); } Timer Timer1; bool mode = false; private void B00nZPictureBox_MouseEnter(object sender, EventArgs e) { mode = true; Timer1 = new Timer(); Timer1.Interval = 10; Timer1.Tick += new EventHandler(Timer1_Tick); Timer1.Start(); } private void B00nZ_MouseLeave(object sender, EventArgs e) { mode = false; Timer1 = new Timer(); Timer1.Interval = 10; Timer1.Tick += new EventHandler(Timer1_Tick); Timer1.Start(); } void Timer1_Tick(object sender, EventArgs e) { int temp = Screen.GetWorkingArea(this).Height; if (mode) { if (this.Height &lt; temp) { this.Size = new Size(this.Width, this.Height + 35); } else if (this.Height &gt; temp) { if (this.Height - temp &gt; 10) { this.Size = new Size(this.Width, this.Height - 3); } else if (this.Height - temp &gt; 0) { this.Size = new Size(this.Width, this.Height - 1); } } else if (this.Height == temp) { Timer1.Stop(); Timer1.Dispose(); } } else { if (this.Height &gt; B00nZPictureBox.Height) { this.Size = new Size(this.Width, this.Height - 35); } else if (this.Height - B00nZPictureBox.Height &lt;= B00nZPictureBox.Height) { this.Size = new Size(this.Width, B00nZPictureBox.Height); } if (this.Height == B00nZPictureBox.Height) { Timer1.Stop(); Timer1.Dispose(); } } setForm(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload