In this article i will teach you how to sliding form.you may have seen some application in which when you click on button Sliding Child Form appear from the main form.I will teach you how to make this kind of sliding form.

Technologies
CShap .net 2.0/3.5
Implementation
For making sliding form effect we need to work with Win32 API functions so to call API's Animation Functions.
So first of all import
using System.Runtime.InteropServices;
here we are calling WIN32 API function so we need to declare some constant values that will be used by function when calling it
so declare all the constants in global area of the class.
//Constants
const int AW_SLIDE = 0X40000;
const int AW_HOR_POSITIVE = 0X1;
const int AW_HOR_NEGATIVE = 0X2;
const int AW_BLEND = 0X80000;
[DllImport("user32")]
static extern bool AnimateWindow(IntPtr hwnd, int time, int flags);
Write code in overrides OnLoad Event of the form which you want to Slide
protected override void OnLoad(EventArgs e)
{
//Load the Form At Position of Main Form
int WidthOfMain=Application.OpenForms["MainForm"].Width;
int HeightofMain= Application.OpenForms["MainForm"].Height;
int LocationMainX=Application.OpenForms["MainForm"].Location.X ;
int locationMainy=Application.OpenForms["MainForm"].Location.Y;
//Set the Location
this.Location = new Point(LocationMainX+WidthOfMain,locationMainy+10);
//Animate form
AnimateWindow(this.Handle, 500, AW_SLIDE |AW_HOR_POSITIVE);
}
here in code we need to set the Sliding Window Location according to the Main window so we need to Code Some extra lines so that
sliding form can slide from proper place.
and Finally I am showing you how whole code will look alike I have Two Forms MainForm from which i press Slide Button and Another Form which will slide ie Form1
MainForm Code
-------------
namespace SlidingEffect
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
bool IsOpen = false;
FormCollection fc = Application.OpenForms;
foreach (Form f in fc)
{
if (f.Name == "Form1")
{
IsOpen = true;
f.Focus();
break;
}
}
if (IsOpen == false)
{
Form1 form = new Form1();
form.Show();
}
}
}
}
Form1 Code (form Which will Slide From MainForm)
----------------------------------------------------
public partial class Form1 : Form
{
//Constants
const int AW_SLIDE = 0X40000;
const int AW_HOR_POSITIVE = 0X1;
const int AW_HOR_NEGATIVE = 0X2;
const int AW_BLEND = 0X80000;
[DllImport("user32")]
static extern bool AnimateWindow(IntPtr hwnd, int time, int flags);
public Form1()
{
InitializeComponent();
}
protected override void OnLoad(EventArgs e)
{
//Load the Form At Position of Main Form
int WidthOfMain=Application.OpenForms["MainForm"].Width;
int HeightofMain= Application.OpenForms["MainForm"].Height;
int LocationMainX=Application.OpenForms["MainForm"].Location.X ;
int locationMainy=Application.OpenForms["MainForm"].Location.Y;
//Set the Location
this.Location = new Point(LocationMainX+WidthOfMain,locationMainy+10);
//Animate form
AnimateWindow(this.Handle, 500, AW_SLIDE |AW_HOR_POSITIVE);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
Conclusion :
Article teaches how to create sliding effect in Windows form application.

ALLAH Rakha ShaibPosted Jan 14, 2015, 1:46 AM
Good, now what changes should i made if i want to slide form in Y direction , swipe up
Mithun MPosted Nov 11, 2014, 5:43 AM
Great tutorial. Could you please tell me some other system\third party libraries which can be used to change the look and feel of the Windows Forms?
katadi rajeshPosted Aug 13, 2013, 1:23 AM
helon sir i want to learn more about System.Runtime.InteropServices i want to knw how and why u included globalconstants
Vinay NamaPosted Jun 13, 2013, 9:22 AM
where can find user32 dll???
Suraj PalapathwelaPosted Mar 25, 2013, 6:32 AM
Great tutorial. Thank you very much for publishing this!
harry virkPosted Mar 9, 2013, 3:55 AM
great work
ross apoloPosted Oct 11, 2012, 4:46 PM
thanks for this example
Vishal JadavPosted Nov 12, 2011, 5:54 AM
good example ...
bikash karmokarPosted Feb 5, 2011, 5:47 AM
thanks for this...
mohit mmPosted Jan 20, 2011, 4:45 PM
Hey Kiran, Above code is very usefull. Thanks for it .I need a code , which look like a downward slider . i want to point out one thing , in this you have taken another form (form 2), which come out as slider .. , is there any way to do it in single form ? means in only one form i want to make downward slider.Main form has one button , and on clicking the button a downward slider come ... which contain a chunk of buttons or link labels of the main form .... is it possible to do like this ? kindly help ...
netron netronsPosted Jan 17, 2011, 6:12 PM
Thanks.
Dipa AhujaPosted Dec 14, 2010, 12:56 PM
this is really cool animation
Amit TankPosted Sep 21, 2010, 2:48 AM
Thanks This is Really Fantastic
Dorababu MekaPosted Sep 2, 2010, 8:09 AM
Good article