• 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

    • Joplin 3.3.13 by Razvan Serea Joplin is a free, open source note taking and to-do application, which can handle a large number of notes organised into notebooks. The notes are searchable, can be copied, tagged and modified either from the applications directly or from your own text editor. Notes exported from Evernote can be imported into Joplin, including the formatted content (which is converted to Markdown), resources (images, attachments, etc.) and complete metadata (geolocation, updated time, created time, etc.). Plain Markdown files can also be imported. The notes can be securely synchronised using end-to-end encryption with various cloud services including Nextcloud, Dropbox, OneDrive and Joplin Cloud. Full text search is available on all platforms to quickly find the information you need. The app can be customised using plugins and themes, and you can also easily create your own. The application is available for Windows, Linux, macOS, Android and iOS. A Web Clipper, to save web pages and screenshots from your browser, is also available for Firefox and Chrome. Features Web Clipper for Firefox and Chrome. End To End Encryption (E2EE). Note history (revisions). Synchronisation with various services, including Nextcloud, Dropbox, WebDAV and OneDrive. Offline first, so the entire data is always available on the device even without an internet connection. Import Enex files (Evernote export format) and Markdown files. Export JEX files (Joplin Export format) and raw files. Support notes, to-dos, tags and notebooks. Sort notes by multiple criteria - title, updated time, etc. Support for alarms (notifications) in mobile and desktop applications. Markdown notes, which are rendered with images and formatting in the desktop and mobile applications. Support for extra features such as math notation and checkboxes. Choice of both Markdown and Rich Text (WYSIWYG) editors. File attachment support - images are displayed, other files are linked and can be opened in the relevant application. Inline display of PDF, video and audio files. Goto Anything feature. Search functionality. Geo-location support. Supports multiple languages. External editor support - open notes in your favorite external editor with one click in Joplin. Extensible functionality through plugin and data APIs. Custom CSS support for customisation of both the rendered markdown and overall user interface. Customisable layout allows toggling, movement and sizing of various elements. Keyboard shortcuts are editable and allow binding of most Joplin commands with export/import functionality. Joplin 3.3.13 changelog: Fixed: Fix printing (#12244) (#12240 by @personalizedrefrigerator) Download: Joplin 3.3.13 | Joplin Portable | ~300 MB (Open Source) Download: MacOS | Android | Linux | iOS View: Joplin Home Page | GitHub project page Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Apple: lets take our inspiration from Windows 7/Vista and call it innovative
    • Nice! My $100 refurbished iPad 8 that I bought last year for a small project (and still runs like new cuz it's been mostly in storage the past several months) will get this v26 upgrade. I'm definitely gonna scope out OS26 on this device before upgrading my also-supported refurbished iPhone SE 3rd Gen (only got it for the 5G UW support).
    • Hello, The separate discussion about VLC has been moved to its own thread at  Regards, Aryeh Goretsky  
    • Hello, I am guessing this is the result of using a third-party tweaking tool instead of changing things within Windows settings. Windows 11 has a decent set of configuration options for the display, but they tend to be scattered throughout the operating system due to fragmentation of product ownership/inconsistent standards being applied by Microsoft. There are a few places in Windows 11 where you can modify the various display settings in order to get them to your liking: Under Settings → System → Display you can stroll down to the Scale & layout section and change the Scale and Display resolution settings to whatever you prefer.  For the Scale option, you can click on the text box to choose between the various pre-populated settings.  If none of those are exactly what you are looking for, click on the caret ("") caret to open the Custom scaling setting (also available under Settings → Display → Custom scaling).  I would recommend this as an option of last resort as this can cause display issues in various programs. I strongly recommend using the screen's native Display resolution here; it should show up as the "(Recommended)" resolution.  If it does not, you may need to install your monitor's profile information file (basically, a device driver for your monitor) to get the correct setting. Another place to look at making changes to fonts is under Accessiblity → Text size.  There is a slider bar for changing the text size from 100% to 225% there. You can try making changes to the ClearType settings.  It's a little bit finer-grained than the others, but it may make the text easier to view on the display.  Run the ClearType Text Tuner (filename: CTTUNE.EXE) and go through the wizard. You may want to do this several times under different lighting conditions or times of the day to figure out what works best for you overall. Lastly, you may want to look into using a dedicated assistive screen technology program from a third-party.  Microsoft provides a Screen Magnifier and a Narrator for text-to-speech, but they provide only basic functionality, and you may find that a third-party program works a lot better.  The pros of this is that third-party assistive technology programs tend to work quite well under Windows; Microsoft has historically worked closely with third-party developers of assistive technologies.  The cons of this are that such tools tend to be on the expensive side, since they are often sold to schools, businesses, or paid for by insurance companies, not individuals. Regards, Aryeh Goretsky  
  • Recent Achievements

    • Dedicated
      MadMung0 earned a badge
      Dedicated
    • Rookie
      CHUNWEI went up a rank
      Rookie
    • Enthusiast
      the420kid went up a rank
      Enthusiast
    • Conversation Starter
      NeoToad777 earned a badge
      Conversation Starter
    • Week One Done
      VicByrd earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      506
    2. 2
      ATLien_0
      267
    3. 3
      +FloatingFatMan
      257
    4. 4
      Edouard
      203
    5. 5
      snowy owl
      178
  • Tell a friend

    Love Neowin? Tell a friend!