• 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
https://www.neowin.net/forum/topic/227988-vbnet-form-slide-effect/
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

  • 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.

  • 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

  • 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
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • I'll have to buy again half of my Xbox games to play them on PC because they are not "play anywhere" titles.
    • Good luck running your Xbox games on PC handheld.
    • https://www.reddit.com/r/pcmas...ick_menu_taking_so/kznvoqq/
    • Hehe, Outer Worlds was the first game that was like "We've noticed you've been dying a lot recently, do you want to get this free perk that will make you die less, but will make your stamina go down faster by 7% ?" One of better games I've ever played and I actually found it by chance on Reddit or something. Didn't know it existed, it was released for a while at that point and I decided to give it a try since I like RPG's with guns more over RPG's with swords and bows. And I absolutely loved it so I can't wait for its sequel. After disappointment of Starfield that was too big and too generic, Outer Worlds 2 will hopefully just be a bit larger single solar system with unique planets in it just like the first one. It was such a good concept. Year 2025 is really loaded with so many awesome games and more to come!
    • Gears of War: Reloaded multiplayer beta kicks off this weekend, here's how to get access by Pulasthi Ariyasinghe Microsoft announced Gears of War: Reloaded earlier this year, unveiling a complete remaster of the first game in the hit action franchise that lets players jump into the classic with a fresh coat of paint. Today during the Xbox Games Showcase, the $40 experience was given another look, and a couple of betas were revealed too. The multiplayer beta will be kicking off on June 13 and ending on June 15 as the first of the weekend access events. The next multiplayer beta will begin on June 20 and run through June 22. The first weekend will feature classic team deathmatch across Gridlock, Raven Down, and Gold Rush maps. Next, the second weekend is adding on the King of the Hill mode on the map Canals. Team deathmatch will still be running this weekend too, and Courtyard and War Machine will be added to the roster. Unfortunately, these aren't open betas, but Microsoft revealed three ways players can jump into the experience to try it out. First off, Gears of War: Ultimate Edition digital owners will receive an invite without having to do anything. All Xbox Game Pass Ultimate and PC Game Pass subscribers are gaining access for no extra cost too. Lastly, anyone who has pre-ordered Gears of War: Reloaded will gain access to the multiplayer beta as well. For those who missed it, the remaster is touting 4K 60FPS in the campaign, 120FPS in multiplayer, enhanced assets and effects, improved shadows, zero loading screens, crossplay, and more features. Check out our original coverage for all the information. Gears of War: Reloaded launches on PC, Xbox Series X|S, PlayStation 5, and Xbox Cloud Gaming on August 26, 2025. It will also be a day one release on Xbox Game Pass Ultimate and PC Game Pass subscriptions for no extra cost. Moreover, Gears of War: Reloaded will be a free upgrade to all Gears of War: Ultimate Edition owners. It needs to have been purchased prior to May 5, 2025 though.
  • Recent Achievements

    • First Post
      George Almeyda earned a badge
      First Post
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
    • Reacting Well
      Lazy_Placeholder earned a badge
      Reacting Well
    • Dedicated
      Epaminombas earned a badge
      Dedicated
    • Veteran
      Yonah went up a rank
      Veteran
  • Popular Contributors

    1. 1
      +primortal
      470
    2. 2
      +FloatingFatMan
      265
    3. 3
      ATLien_0
      235
    4. 4
      snowy owl
      219
    5. 5
      Edouard
      172
  • Tell a friend

    Love Neowin? Tell a friend!