• 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

    • Jony Ive is reportedly working on multiple AI devices for OpenAI, including a mobile gadget by Hamid Ganji Last month, OpenAI announced acquiring Jony Ive's startup, io, in a $6.5 billion deal. Ive, who served as Apple's design chief for over two decades, moved to OpenAI to work on the company's AI hardware projects. While the details of these projects have remained relatively untold, Mark Gurman's Power On newsletter revealed some exciting insights about Jony Ive's work at OpenAI. According to Gurman, Apple's former design chief is now spearheading a series of groundbreaking AI hardware products for OpenAI. One of these under-development devices is described as a "mobile gadget" that takes the form of a "pendant" and can be worn around the neck. This device could allegedly allow users to access ChatGPT with voice commands. Another of Ive's works at OpenAI is a home device that functions similarly to a smart speaker. Users can put the device on a table and perform various tasks using OpenAI's ChatGPT. Interestingly, OpenAI also has a robot device under development. As Gurman says, this robot "will likely be a machine that develops a relationship with a human using AI." However, OpenAI's robot is still far from being made available on the market. After acquiring Jony Ive's startup, OpenAI CEO Sam Altman described Ive as the best designer in the world, adding that they can now work on the next generation of AI-powered computers. More details about OpenAI-Ive hardware products could emerge over the next few months. OpenAI was already rumored to be working on a mysterious AI gadget, presumably a screenless AI phone, which might be the same mobile gadget that Gurman revealed. While details of this alleged AI mobile are yet unknown, such a device could pose an alternative to conventional smartphones, raising the alarm for smartphone makers such as Apple, Samsung, and Google. Meanwhile, Apple might already be expecting such a device, as its services chief Eddy Cue allegedly said during his testimony at Google's antitrust case that iPhones might no longer exist 10 years from now.
    • Seems Nintendo have already thought of that after the Joy-Con drift in the Switch 2 EULA: Clause 16 of the EULA reads: "This arbitration provision precludes you and Nintendo from suing in court, having a trial by jury, or participating in a class action. You and Nintendo agree that arbitration will be solely on an individual basis and not as a class arbitration, class action, or any other kind of representative proceeding. You and Nintendo are each waiving the right to trial by a jury."
    • Cool glass phone you have in that silicon case bro
    • I can't say I ever noticed an OEM putting effort into user-friendly descriptions and icons who didn't also put effort into making good drivers. Usually, missing icons and descriptions was also a sign of bad drivers.
  • Recent Achievements

    • First Post
      brynmot earned a badge
      First Post
    • Reacting Well
      brynmot earned a badge
      Reacting Well
    • Week One Done
      Al_ earned a badge
      Week One Done
    • Week One Done
      MadMung0 earned a badge
      Week One Done
    • Reacting Well
      BlakeBringer earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      477
    2. 2
      +FloatingFatMan
      274
    3. 3
      ATLien_0
      243
    4. 4
      snowy owl
      209
    5. 5
      Edouard
      185
  • Tell a friend

    Love Neowin? Tell a friend!