PDA

View Full Version : VBA Sliding Form/Menu



BlueDNA
12-05-2005, 08:24 PM
Hi all,

im just curious, is it possible to have a main form with a button on the side that when clicked simulates the effect of sliding out a sub form/menu. When a user fills in the details they can click the button again allowing the form to slide back into the main form.

Thanks.

:hi:

fumei
12-06-2005, 12:24 AM
You can do it in VB, and I would think it would be possible to do it in VBA - although I am not sure about the animation of "sliding" it out. You have to use two forms and VERY precise screen locators.

This may well be an excellent example of "just because you CAN doesn't mean it is worth it...or that it is good."

It would take a lot to fuss VBA into doing it, and for what end? It would not be a starting project, that's for sure.

fumei
12-06-2005, 12:25 AM
But there may be third-party software that does it...

Killian
12-06-2005, 04:14 AM
I'd say this were possible, but Gerry makes a good point - you're going to need to employ some slightly more advanced techniques that "pure" VBA to achieve it.

Positioning the sub-form as it moves out will be quite straight-forward since it will be relative to the main form but in order to animate the transition, this movment will need to be stepped in small time increments - fractions of a second, so you need an accurate timer - VBA gives you access to the time in a few ways but it's to the nearest second... you'll need to construct a timer that works in milliseconds.

This thread (http://www.vbaexpress.com/forum/showthread.php?t=4247) has a related discussion - have a look at the attachment on post 12 (http://www.vbaexpress.com/forum/showpost.php?p=35759&postcount=12) to see an example of how this can be done.

However your requirement throws up a couple of challenges:
1) the subform will be on top of the main form (if a modal form is loaded, any subsequent form must also be modal) - it really needs to appear to slide out from behind
2) The attached example is easy because when the animation is finished, the form is unloaded so the timer can be stopped and disposed of in the Terminate event. Your subform will still be showing so unless you want to leave the timer running, you need to raise an event when the form is displayed to stop it
3) You are probably going to need to remove the subform's controlbox and border so the user can't move it around

So yes, I think it's do-able but getting it to work right while looking sharp and well-integrated is going to make it quite complex

Andy Pope
12-06-2005, 05:01 AM
Hi,

Maybe you could put the subform controls in a frame and then resize the userform to reveal and hide that part.
This simple example just unfolds the bottom of the userform. Create a userform and add a commandbutton.
Private Sub CommandButton1_Click()
With CommandButton1
If .Caption = "Expand" Then
Do While Me.Height < 250
Me.Height = Me.Height + 0.1
DoEvents
Loop
.Caption = "Contract"
Else
Do While Me.Height > 170
Me.Height = Me.Height - 0.1
DoEvents
Loop
.Caption = "Expand"
End If
End With
End Sub
Private Sub UserForm_Initialize()
With Me
.Width = 200
.Height = 170
End With
With CommandButton1
.Top = 100
.Left = 100
.Width = 75
.Height = 25
.Caption = "Expand"
End With
End Sub

fumei
12-06-2005, 09:17 AM
The point is that while it is do-able, it is NOT trivial. Yes, you can make something like it.

I often do dynamically resize a form as it looks cool, and that way you can often keep controls on one form, rather than sub-forms. However, you can only expand a form within the context of the original dimensions. That is, you can expand (make visible) along the full dimension of an axis. ALL of the .Height, or ALL of the .Width. You can not duplicate a "flyout" form that is, say, 25% of the .Height.

So....again....yeah it is POSSIBLE...but why go through all that effort? Just to be cute? That is what it seems to me. There are so many other useful things to do with code. There is enough cuteness around. Does it enhance the useability for the user? Doubtful. The same effort going into really good design would be far more useful.

BlueDNA
12-06-2005, 04:13 PM
Hi and thanks for the replies.

Being "cute" would probably be the most accurate description. I have already developed alternative user friendly menu's and efficient navigational structures ever since the initital post.

But the concept of a sliding menu has always been apparent in the back of my mind. Ideally i would envisage developing both concepts and testing the effectiveness, efficiency and limitations of both. However, "ideal" does not always collide alongside with expectancy. :yes

Thanks Andy, that concept produces a great illusion of a sliding effect and is almost exactly what i was looking for!

Im quite happy with what i have designed, but will definately attempt to be cute when time permits! Thanks for all the suggestions! Appreciate it.

:hi: