• 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

    • Microsoft design looked better at the time.
    • Mozilla really should start cutting paychecks of management, CEO and so on. Like they don't have resources, but easily spend millions on that. While decisions of those people lost them ton of money with stuff like services they are now shutting down. And overall I think they got too many people on top too. P.S. Also those sane people on top failed to notice or act on how Google money could go away and do something about it, like alternate sources of revenue. They had many years of ignoring it.
    • WinRAR 7.12 Beta 1 by Razvan Serea WinRAR is an archiving utility that completely supports RAR and ZIP archives and is able to unpack CAB, ARJ, LZH, TAR, GZ, UUE, BZ2, JAR, ISO, 7Z, Z archives. It consistently makes smaller archives than the competition, saving disk space and transmission costs. WinRAR offers you the benefit of industry strength archive encryption using AES (Advanced Encryption Standard) with a key of 128 bits. It supports files and archives up to 8,589 billion gigabytes in size. It also offers the ability to create self extracting and multi volume archives. With recovery record and recovery volumes, you can reconstruct even physically damaged archives. WinRAR 7.12 Beta 1 changelog: When extracting a file, previous versions of WinRAR, Windows versions of RAR, UnRAR, portable UnRAR source code and UnRAR.dll can be tricked into using a path, defined in a specially crafted archive, instead of user specified path. Unix versions of RAR, UnRAR, portable UnRAR source code and UnRAR library, also as RAR for Android, are not affected. We are thankful to whs3-detonator working with Trend Micro Zero Day Initiative for letting us know about this security issue. Previously "Generate report" command included archived file names into HTML report as is, allowing to inject potentially unsafe HTML tags into the report. To prevent such injection the current version replaces < and > file name characters in HTML report with < and > strings. We are thankful to Marcin Bobryk (github.com/MarcinB44) for bringing this security issue to our attention. If "Test archived files" and "recovery volumes" archiving options are used together, recovery volumes are also tested. Previous versions completed the test before creating recovery volumes, so they hadn't been verified. Nanosecond file time precision is preserved for Unix file records when modifying RAR archive in Windows. Previously it was converted to Windows 100 nanosecond precision. Download: WinRAR 64-bit | 3.7 MB (Shareware) Links: WinRAR Website | WinRAR Themes | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • 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
      506
    2. 2
      ATLien_0
      269
    3. 3
      +FloatingFatMan
      241
    4. 4
      +Edouard
      201
    5. 5
      snowy owl
      163
  • Tell a friend

    Love Neowin? Tell a friend!