• 0

[VB.NET] Form Slide Effect


Question

Hi,

I have created this little slide effect in my app, but it's something simple. Like, a timer with 1ms interval wich will move the form in that interval with a code like: Me.Location = New Point(X, Y)

of course I add a few more lines so the form don't keep sliding and sliding to the infinite and a variable taht increases/decreases so the form is moved...

However, is there a better way to do this? This looks like a bit odd way to do it... And I wanted to add a speed feature for the slide effect but it's a pain in the ass to make it with different speeds and at the same time smooth in the slide effect an dI also need to keep in consideration the form's size and the multiple of pixels that will move the form so the start and finish positions are always the same no matter the speed...

Any good away to achive this?

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Thanks, that helped me and I could just the effect I wanted but with some problems.

It is working as I want but here's my problems:

- After the window is completely drawn on the screen I want it to be focused but I tried f1.Focus, f1.Show, f1.Activate but it doesn't work.

- The child controls (button, frame, textbox) are not drawn until the window is fully dranw, how an this be solved?

- I wanted the button 'Hide' to hide the form back from where it came... but I can't find a way to hide it, AW_HIDE does not seem to be working properly... I must be doing something wrong.

Can you help me?

Here's the source files: http://www.nazgulled.net/WindowsApplication1.zip

Link to comment
Share on other sites

  • 0

ok i managed to sole ur first two problems, but havent got the hiding working

ok so first of all

instead of claling animate window in ur sub main

make it a function and put this in your module

Sub animateWin(ByVal frmToAnimate As Form)

AnimateWindow(frmToAnimate.Handle, 1000, AnimateWindowFlags.AW_HOR_NEGATIVE Or AnimateWindowFlags.AW_SLIDE)

End Sub

and then in your Form1, in the form load event

put:

animateWin(me)

and that's it, now you see the controls drawn out and also the form gets focused.

Link to comment
Share on other sites

  • 0

ok i got all your problems fixed

here's the module file

Module Module1

    Public Enum AnimateWindowFlags
        AW_HOR_POSITIVE = &H1
        AW_HOR_NEGATIVE = &H2
        AW_VER_POSITIVE = &H4
        AW_VER_NEGATIVE = &H8
        AW_CENTER = &H10
        AW_HIDE = &H10000
        AW_ACTIVATE = &H20000
        AW_SLIDE = &H40000
        AW_BLEND = &H80000
    End Enum

    Dim f1 As Form1

    Public Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal time As Integer, ByVal flags As AnimateWindowFlags) As Boolean

    Sub Main()
        f1 = New Form1
        Dim xx As Integer = Screen.PrimaryScreen.Bounds.Width - f1.Size.Width
        Dim yy As Integer = Screen.PrimaryScreen.Bounds.Height / 2 - (f1.Size.Height / 2)
        f1.Location = New Point(xx, yy)
        Application.Run(f1)
    End Sub

    Sub animateWin(ByVal frmToAnimate As Form, ByVal showForm As Boolean)
        If showForm Then
            AnimateWindow(frmToAnimate.Handle, 1000, AnimateWindowFlags.AW_HOR_NEGATIVE Or AnimateWindowFlags.AW_SLIDE)
        Else
            AnimateWindow(frmToAnimate.Handle, 1000, AnimateWindowFlags.AW_HOR_POSITIVE Or AnimateWindowFlags.AW_HIDE)
        End If

    End Sub


End Module

and here's the Form code which shows how to use it:

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        animateWin(Me, True)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        animateWin(Me, False)
        Application.Exit()
    End Sub

Link to comment
Share on other sites

  • 0

That really worked out on my standalone example... However, doesn't work in the real app wich I'm doing (I'm talking about this: https://www.neowin.net/forum/index.php?showtopic=217253)

In my real application, the problems are in focusing the form and show the child controls with the slide effect. The hide thing is working, it was just a manner of calling the API correctly, thank you.

The differences between thta standalone example and my real app is that in my standalone example I use Application.Run(f1) and on my real app I use just Application.Run() because I want the form to start hidden. But if I do like that, the child forms do not appear when sliding the form.

If you download the application you'll see that I want the app to start hidden and then with a notifyicon, I show or hide the form (depends of course if it's already shown or not).

Any help possible on this? :)

---------------------- EDIT ----------------------

I just tried on my real live app with Application.Run() and with the following code for the notifyicon click event:

Private Sub notifyIcon_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles notifyIcon.MouseUp
        If (e.Button = MouseButtons.Left) Then
            If (frmMainVisible) Then
                slideNotesForm(Me, False)
                frmMainVisible = False
            Else
                slideNotesForm(Me, True)
                frmMainVisible = True
            End If
            'End If
        End If
    End Sub

Public Sub slideNotesForm(ByVal frmThis As Form, ByVal inViewport As Boolean)
        If (inViewport) Then
            AnimateWindow(frmThis.Handle, 250, AnimateWindowFlags.AW_HOR_NEGATIVE Or AnimateWindowFlags.AW_SLIDE)
            frmMain.Show()
            frmMain.Activate()
        Else
            AnimateWindow(frmThis.Handle, 250, AnimateWindowFlags.AW_HOR_POSITIVE Or AnimateWindowFlags.AW_SLIDE Or AnimateWindowFlags.AW_HIDE)
        End If
    End Sub

And it works just fine besides the first time the form slides into the screen. The form at start is hidden and the first time I click on the notifyicon the child controls are drawn after the slide effect but after that, everytime I slide in or out, the child controls are always visible.

Edited by Nazgulled
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.