Daniel Daniel - 1 year ago 256
C# Question

Winforms load animation

I've created some code in my

event that adds adds an animation to my WinForms application so it appears in the buttom right corner and slides up from below the taskbar:


private void button1_Click(object sender, EventArgs e)
int x = SystemInformation.VirtualScreen.Width/2 - 290;
int y = SystemInformation.VirtualScreen.Height - 90;

Point p = new Point(x, y);
this.Location = p;

for (int i = 0; i < 150; i++)
this.Location = p;

The result

enter image description here

Now I want my form to open with this animation when created, so I've tried moving my code to the
event, but for some reason it doesn't work. It just loads normally.

Answer Source

Move your animation code to the Form.Shown event handler. I would recommend to you still set the initial position in the Form.Load as to avoid a momentary flash of the form at its default position.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download