• 0

[VB.NET] Moving a form


Question

I have a timer to move a form up frmNotification.Height in ShowTime milliseconds..

   Private WithEvents tmrTimer As New System.Windows.Forms.Timer

... (called in a function)
        tmrTimer.Interval = Math.Floor(ShowTime / frmNotification.Height)
        tmrTimer.Enabled = True
...

    Private Sub tmrTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrTimer.Tick
        frmNotification.Top -= 1
        If (frmNotification.Top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - frmNotification.Height - 28) Then
            tmrTimer.Enabled = False
        End If
    End Sub

But it goes very slow no matter what the timer is set at.. is there another way I could move it up without blocking (a loop in another thread maybe?) or do I have to use some kind of high resolution timer?

Edited by todd`
Link to comment
https://www.neowin.net/forum/topic/201336-vbnet-moving-a-form/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Well, it's moving very slowly because you're only moving it up one pixel at a time. If you want it to move faster, you can either move it up further each tick, or use a System.Timers.Timer (as opposed to Windows.Forms.Timer). It has a higher resolution, so the speed still increases when you lower the interval below 100 (the SWF timer may or may not speed up).

  • 0

Thanks for the suggestions.. The AnimateWindow API seems the easiest and that's what I'm trying to get working..

AnimateWindow(frmNotification.Handle.ToInt32, ShowTime, &H8)

..is what I have, but nothing happens and when I print the result, it's False. The form is hidden at the time this function is called so I don't know what's wrong (yes, I added the declaration ;)).

  • 0

don't use AllApi for Vb.NET. use http://www.pinvoke.net instead.

http://www.pinvoke.net/default.aspx/user32.AnimateWindow

   <FlagsAttribute()> _
    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
    Public Declare Auto Function AnimateWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal time As Integer, ByVal flags As AnimateWindowFlags) As Boolean


'Usage
        Dim f2 As Form2
        f2 = New Form2
        AnimateWindow(f2.Handle, 1000, AnimateWindowFlags.AW_VER_NEGATIVE Or AnimateWindowFlags.AW_SLIDE)
        f2.Show()

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

    • No registered users viewing this page.
  • Posts

    • I am afraid to ask but what specific crowd are you talking about? Most people wanted Mozilla to concentrate on the browser but of course are still complaining when they do that. Anyway Firefox works just fine for me. We all deserve the Chrome only future that is coming.
    • Such a missed opportunity for a company with arena sized buckets of cash. The first on device AI and they never really improved it all those years. They could have been leading this charge.
    • Glow 25.06 by Razvan Serea Glow provides detailed reporting on every hardware component in your computer, saving you valuable time typically spent searching for CPU, motherboard, RAM, graphics card, and other stats. With Glow, all the information is conveniently presented in one clean interface, allowing you to easily access and review the comprehensive hardware details of your system. Glow provides detailed information on various system aspects, including OS, motherboard, processor, memory, graphics card, storage, network, battery, drivers, and services. The well-organized format ensures easy access to the required information. You can export all the gathered data to a plain text file, facilitating sharing with others for troubleshooting purposes. No installation needed. Just decompress the archive, launch the executable, and access computer-related information. Glow runs on Windows 11 and Windows 10 64-bit versions. Glow 25.06 release notes: What's new Support provided for Windows 11 24H2 May 2025 update. Support provided for Intel Arrow Lake-H series processors. Support for AMD Ryzen AI series processors. Support for NVIDIA RTX 50 series graphics cards. Support for AMD RX 9000 series graphics cards. Support for processors and graphics cards from Intel, AMD and NVIDIA until May 2025. Support for GDDR7 graphics memory. .NET Framework June 2025 security update has been integrated. Fixed Bugs Fixed DPI bug in the Memory Test Tool that caused buttons to be nested with the table at 150% DPI and above. Fixed a translation bug in the Cache Cleanup Tool that caused an incorrect character encoding set in the Russian language. Fixed various DPI bug and character encoding bug fixes. Note: Always unzip the program before using it. Otherwise you may get an error. Download: Glow 25.06 | 2.0 MB (Open Source) View: Glow Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • How to enable the redesigned Windows 11 Start menu by Taras Buria This week, Microsoft started testing a big redesign for Windows 11's Start menu. It is now rolling out to Windows Insiders in the Dev and Beta Channels, addressing quite a few pain points in the original Start menu, which was shipped in late 2021. Nearly four years later, we finally have the long-anticipated redesign (announced earlier this year). The updated menu now features a single-page view, with all your pins and apps on one scrollable page. You can change the list of all apps between three variants: list, grid, and category. More importantly, you can now hide the recommended section in the Start menu settings (one of the most requested Start menu-related changes). The new Start menu is available in this week's Dev and Beta update. However, like always, Microsoft is rolling out changes gradually, which means you might not have the lucky ticket even on the latest build. If you do not want to wait, you can force-enable the new Start menu and its Phone Link button using a few commands in the ViVeTool app. Here is how to do that: Download ViveTool from GitHub and unpack the files in a convenient and easy-to-find folder. Run Command Prompt as Administrator and navigate to the folder containing the ViveTool files with the CD command. For example, if you have placed ViveTool in C:\Vive, type CD C:\Vive. Type vivetool /enable /id:47205210,49221331,49381526,49402389,49820095,55495322,48433719 and press Enter. Restart your computer. As usual, keep in mind that stuff in preview builds is less stable, so be aware of the risks of running preview builds. While Microsoft is not saying when the new Start menu will be available to all users, it will probably not take too long before it shows up in Release Preview and non-security updates. By the way, if you are curious, check out some of the prototypes that Microsoft considered when designing the new Start menu. Credit for the IDs goes to @phantomofearth on X.
    • reddit's "bottom of the barrel" > 99% of neowin front page "news"
  • Recent Achievements

    • Week One Done
      IAMFLUXX earned a badge
      Week One Done
    • One Month Later
      Æhund earned a badge
      One Month Later
    • One Month Later
      CoolRaoul earned a badge
      One Month Later
    • First Post
      Kurotama earned a badge
      First Post
    • Collaborator
      Carltonbar earned a badge
      Collaborator
  • Popular Contributors

    1. 1
      +primortal
      505
    2. 2
      ATLien_0
      268
    3. 3
      +FloatingFatMan
      234
    4. 4
      +Edouard
      201
    5. 5
      snowy owl
      162
  • Tell a friend

    Love Neowin? Tell a friend!