C.M.W.
C.M.W.

Reputation: 145

How to show and hide form using sliding effect of AnimateWindow function using c#?

I am using windows form for my application. I am loading another form on click of panel. Now I want to show sliding effect for opening and closing of form.I am able to add negative sliding effect while opening as form opens from right to left by overloading OnLoad event of form. But I am not able to hide the form with positive slide effect using AnimateWindow function. Is there any way to do this?

This is what I have used to show the form:

protected override void OnLoad(System.EventArgs e)
{
  NativeMethods.AnimateWindow(this.Handle, 500, 
                  AW_ACTIVATE | AW_SLIDE | AW_HOR_NEGATIVE);

  base.OnLoad(e);    
}

Upvotes: 2

Views: 7973

Answers (3)

John Arlen
John Arlen

Reputation: 6689

Using your existing pattern - OnClosing + AW_HIDE does it in reverse.

protected override void OnClosing(CancelEventArgs e)
{
   AnimateWindow(this.Handle, 500, AW_ACTIVATE | AW_SLIDE | AW_HOR_NEGATIVE | AW_HIDE);

   base.OnClosing(e);
}

Upvotes: 2

Laoujin
Laoujin

Reputation: 10229

This library might be able to do what you want.

Example code from the site, which could, in your case, be placed in the Closing event.

Transition t = new Transition(new TransitionType_EaseInEaseOut(2000));
t.add(pictureBox1, "Left", 300);
t.add(pictureBox1, "Top", 200);
t.run();

Once you've done the animation, you can use the TransitionCompletedEvent event to hide the form. (or you could animate the Opacity property of your form)

public event EventHandler<Args> TransitionCompletedEvent;

Upvotes: 1

Tigran
Tigran

Reputation: 62256

Why don't use simply Form.Location property.

Increase or decrease it's relative values to achieve sliding animation effect you want.

Upvotes: 1

Related Questions