• 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'd say "no thank you" to Recall. Let's turn it off as quicly as possible when installed. And Microsoft -please- don't let a "bug" re-install/re-configure it again.
    • Let's just wait until Patch Tuesday and have most of the bugs on this KB/download be taken care of & ironed out.
    • Just read that before coming here. So sad 😪 Always been one of my all time favorites whether with Sabbath or solo Glad he got the chance to do his 1 last show. Truly going home now.  
    • It comes just weeks after the Black Sabbath star took to the stage one final time with his band mates at Villa Park in Birmingham. He died "surrounded by love", a statement from his family said on Tuesday night. The family said: "It is with more sadness than mere words can convey that we have to report that our beloved Ozzy Osbourne has passed away this morning. "He was with his family and surrounded by love. We ask everyone to respect our family privacy at this time. "Sharon, Jack, Kelly, Aimee and Louis."     https://www.thesun.co.uk/tvandshowbiz/23619758/ozzy-osbourne-dead-black-sabbath-parkinsons/
    • I hard disagree on Edge being great. I actually spent a lot of time on Internet Explorer, even in the days when IE was basically a dead system and most had already switched to Chrome. I kept using IE because I was basically a Microsoft-fan-boy back then. When I first started using Windows 10, I of course started using Edge. Some things were a lot more responsive, but it had so many issues it basically was unusable. I think it's a pretty big condemnation when someone who was fine using IE11 says that Edge is what finally drove me to start using Chrome. Yes, Edge did get better over its few years before it was replaced, but it had already failed in the minds of most users.
  • Recent Achievements

    • Week One Done
      SmileWorks Dental earned a badge
      Week One Done
    • Community Regular
      vZeroG went up a rank
      Community Regular
    • Collaborator
      Snake Doc earned a badge
      Collaborator
    • Week One Done
      Snake Doc earned a badge
      Week One Done
    • One Month Later
      Johnny Mrkvička earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      586
    2. 2
      Michael Scrip
      197
    3. 3
      ATLien_0
      196
    4. 4
      +FloatingFatMan
      131
    5. 5
      Xenon
      122
  • Tell a friend

    Love Neowin? Tell a friend!