Click here to Skip to main content
15,887,812 members
Articles / Programming Languages / C#

A Slide Form Base

Rate me:
Please Sign up or sign in to vote.
4.94/5 (19 votes)
18 Dec 20022 min read 191.7K   4.8K   102   24
A slide form class from which to derive your forms from

Image 1

Introduction

Some time ago, I needed a form that had a sliding panel on its side. I checked the web to avoid coding. I found a solution on www.codeguru.com. I used and improved the C++/MFC code. Since I use C# for my development, you can find here the result of my work. The form class must be inherited and the specialized form must implement a special constructor. You can find a small example below.

Design of a Simple Slide Form

Use the “Add inherited form” wizard in Visual Studio .NET, and select the SlideForm in the inheritance picker dialog.

Image 2

You’ve got the following form in your project:

Image 3

Resize and customize it with the appropriate controls. Keep in mind that this form will be hidden by the main form, so, ensure that the child form is smaller than the parent:

Image 4

Next, you must provide a special constructor for this slide form. This constructor takes a reference on the parent form and the step of sliding. This step is a percentage of the slide form that will be shown at each tick of timer.

C#
public MySlideForm(Form poOwner, float pfStep) : base(poOwner, pfStep) 
{
    InitializeComponent();
} 

We are done with the sliding form. Now, have a look at the way we will make our slide form slide. First, instantiate the slide form:

C#
// In parent form constructor for instance
oSlideForm = new MySlideForm(this, 0.1f); 
// ...

Next, in the handler of the button that command the sliding of the form, use the following code:

C#
// ...
_oSlideForm.SlideDirection = SlideDialog.SlideDialog.SLIDE_DIRECTION.RIGHT; 
_oSlideForm.Slide(); 
// ...

In this example, the form will slide by the right side of the parent form. That's all! Enjoy!

History

  • December 2002: Initial post

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.


Written By
Software Developer (Senior)
France (Metropolitan) France (Metropolitan)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
NewsI'm port this to WPF Pin
Member 87437343-Nov-23 11:37
Member 87437343-Nov-23 11:37 
QuestionPort to WPF Pin
Member 87437342-Nov-23 11:39
Member 87437342-Nov-23 11:39 
QuestionQuestion Pin
Member 968818415-Jul-13 21:04
Member 968818415-Jul-13 21:04 
GeneralMy vote of 5 Pin
ragavaisr27-Apr-13 22:10
ragavaisr27-Apr-13 22:10 
Questionslide in the opposite direction Pin
Abdul Rahman El Habboub6-Jan-13 23:26
Abdul Rahman El Habboub6-Jan-13 23:26 
QuestionWhen lost focus Pin
karenpayne19-Jun-11 2:06
karenpayne19-Jun-11 2:06 
GeneralMy vote of 4 Pin
karenpayne19-Jun-11 2:04
karenpayne19-Jun-11 2:04 
QuestionHow to design the slide form Pin
rahul_raut17-May-11 22:32
rahul_raut17-May-11 22:32 
GeneralMy vote of 5 Pin
rahul_raut17-May-11 22:29
rahul_raut17-May-11 22:29 
GeneralSome aesthetic issues Pin
Anonymous15-Feb-05 14:10
Anonymous15-Feb-05 14:10 
First off, thanks for the great Control. There are a couple nitpicky issues I have though, and I was curious to get your input on them.

If you have the slide window all the way behind the owner window (fully collapsed) and open a normal dialog from the owner window, it seems that the owner gets sent to the back - and the slide window will be draw on top of the owner until the owner regains focus.

To fix this, I thought it would be as simple as calling Hide() once the window was collapsed, but here is where the "issue" comes in. It seems that Show() (once you want to expand the slide window again) brings the window into focus - and brings it to the front - and there is some flicker where you can see it on top of the owner window for a second before owner.BringToFront() is called.

I can't seem to find any documentation on how it would be possible to override the behavior of Show() in terms of disabling the bring to front action.

My other thought is to slide by resizing the width or height to 0, rather than actually moving the window. Everything would need to be anchored to the side that is sliding out (possibly at runtime in OnLoad()?) and not anchored to the side that the form is growing from, but other than that, it seems like this might be a fair solution.

Other than the listed tradeoffs, is there any reason why this would be a very bad idea?
GeneralRe: Some aesthetic issues Pin
Cookie_Jar8-Jul-06 23:32
Cookie_Jar8-Jul-06 23:32 
GeneralRe: Some aesthetic issues Pin
kaymyst10-May-07 5:26
kaymyst10-May-07 5:26 
GeneralOne problem!! Pin
Kaosu17-Jan-04 22:05
Kaosu17-Jan-04 22:05 
GeneralRe: One problem!! Pin
snarfblam28-Dec-06 14:28
snarfblam28-Dec-06 14:28 
GeneralA SliderWindow does not dock to an MDI child Pin
Mamacita7-May-03 0:09
Mamacita7-May-03 0:09 
GeneralMissed Solution File Pin
Chris Richner22-Dec-02 0:13
Chris Richner22-Dec-02 0:13 
GeneralRe: Missed Solution File Pin
nimbus3d25-Dec-02 3:20
nimbus3d25-Dec-02 3:20 
GeneralRe: Missed Solution File Pin
Chris Richner25-Dec-02 5:07
Chris Richner25-Dec-02 5:07 
GeneralForm plane level Pin
jlwxsf19-Dec-02 13:44
jlwxsf19-Dec-02 13:44 
GeneralRe: Form plane level Pin
nimbus3d25-Dec-02 3:18
nimbus3d25-Dec-02 3:18 
GeneralRe: Form plane level Pin
Stefan Turalski5-Oct-04 1:27
Stefan Turalski5-Oct-04 1:27 
GeneralRe: Form plane level Pin
Stefan Turalski5-Oct-04 2:15
Stefan Turalski5-Oct-04 2:15 
GeneralChanging the rate Pin
Marc Clifton19-Dec-02 8:27
mvaMarc Clifton19-Dec-02 8:27 
GeneralRe: Changing the rate Pin
MyMojo20-Dec-02 18:54
MyMojo20-Dec-02 18:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.