Results 1 to 7 of 7

Thread: Timer object anyone?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Timer object anyone?

    umm how do I work with it?
    I'm declaring a new Timer object and adding a handle to its Elapsed event. Seems like my app hangs for some reason. Is there any dumb things that I can be doing wrnog?
    I'm doing soemthing like this:

    Dim t as new timer(2000)

    ....
    t.start
    addhandler t.elapsed, addressof blah


    this is the whole thing in case you are interested to know. It's supposed to show the button two seconds after the mouse is hovered on the picturebox
    VB Code:
    1. Private t As New Timer(2000)
    2.     Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
    3.         t.Start()
    4.     End Sub
    5.  
    6.     Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    7.         t.Stop()
    8.         Button1.Visible = False
    9.     End Sub
    10.  
    11.     Private Sub MouseHover2Seconds(ByVal sender As Object, ByVal e As ElapsedEventArgs)
    12.         Button1.Visible = True
    13.     End Sub
    14.  
    15.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    16.         AddHandler t.Elapsed, AddressOf MouseHover2Seconds
    17.     End Sub

    very ingenious, right, hehe.
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Timer object anyone?

    Does the code currently work and you're only having the problem with it going slow or does it not work at all?
    Originally posted by MrPolite
    very ingenious, right, hehe.
    annoying !=
    ingenious

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: Re: Timer object anyone?

    Originally posted by kasracer
    Does the code currently work and you're only having the problem with it going slow or does it not work at all?
    annoying !=
    ingenious
    noo aint workin. app hangs and hangs then stops repainting hehe I'm acting like a compelete newbee now
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Why not just use the MouseHover event of the picturebox? Also I thought it was the Tick event you use.
    VB Code:
    1. Private Sub PictureBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseHover
    2.         Button1.Visible = True
    3.     End Sub
    4.  
    5.     Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    6.         'although unless the button is in the picturebox they wont eb able to click it
    7.         'since it will disappear when they leave the picturebox to click it
    8.         Button1.Visible = False
    9.     End Sub

  5. #5

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    umm well! I wanted the button to appear AFTER a delay. Kinda like in IE when you hover over a picture, after a lil while it will show the save/print/bleh buttons I havent used timers so I'm gussing I'm doing something really wrong
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Originally posted by MrPolite
    umm well! I wanted the button to appear AFTER a delay. Kinda like in IE when you hover over a picture, after a lil while it will show the save/print/bleh buttons I havent used timers so I'm gussing I'm doing something really wrong
    Well that is what the MouseHover event does, but if you want more control over the time it takes or really want to use the Timer then:
    VB Code:
    1. Private WithEvents _Timer As New Timer
    2.  
    3.     Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    4.         'although unless the button is in the picturebox they wont eb able to click it
    5.         'since it will disappear when they leave the picturebox to click it
    6.         Button1.Visible = False
    7.         _Timer.Enabled = False
    8.     End Sub
    9.  
    10.     Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
    11.         _Timer.Interval = 2000
    12.         _Timer.Enabled = True
    13.     End Sub
    14.  
    15.     Private Sub _Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _Timer.Tick
    16.         Button1.Visible = True
    17.     End Sub
    There is more than one Timer object so check which one you are using. I am using the one from the Windows.Forms namespace not the Threading namespace one.

  7. #7

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by Edneeis
    Well that is what the MouseHover event does, but if you want more control over the time it takes or really want to use the Timer then:
    VB Code:
    1. Private WithEvents _Timer As New Timer
    2.  
    3.     Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    4.         'although unless the button is in the picturebox they wont eb able to click it
    5.         'since it will disappear when they leave the picturebox to click it
    6.         Button1.Visible = False
    7.         _Timer.Enabled = False
    8.     End Sub
    9.  
    10.     Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
    11.         _Timer.Interval = 2000
    12.         _Timer.Enabled = True
    13.     End Sub
    14.  
    15.     Private Sub _Timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _Timer.Tick
    16.         Button1.Visible = True
    17.     End Sub
    There is more than one Timer object so check which one you are using. I am using the one from the Windows.Forms namespace not the Threading namespace one.
    hmm that one works? I was using teh one from System.Timers
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width