3 Replies - 1193 Views - Last Post: 25 December 2011 - 02:44 PM Rate Topic: -----

#1 aristide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-December 11

[VB.NET] Form Auto-Opening And Closing Question

Posted 25 December 2011 - 12:17 PM

Hello guys!
I need some help on my form in vb.net. I want it to open and close after 3 seconds at each Timer1.Tick
What i got so far:
Me.WindowState = FormWindowState.Minimized
Me.Hide()

And I put this into Timer1.Tick What do i need to add to make it so that Button1.Click does:
Timer1.Enabled = True

and Timer1 should open the form, and after 3 seconds minimize it. Until now I haven't found anything. Does anyone of you know something? Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: [VB.NET] Form Auto-Opening And Closing Question

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4187
  • View blog
  • Posts: 11,845
  • Joined: 18-April 07

Re: [VB.NET] Form Auto-Opening And Closing Question

Posted 25 December 2011 - 12:36 PM

Here is the code which will minimize and hide the form after 3 seconds. Notice the button event will set the interval of the timer to 3000 milliseconds (3 secs) and at which time will kick off the tick event. At the end of the event we will stop the timer.

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Me.WindowState = FormWindowState.Minimized
        Me.Hide()
        Timer1.Stop()
    End Sub



Now the button to trigger this tick event. We use the start() method to start the timer...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Interval = 3000
        Timer1.Start()
    End Sub



Set the interval, then start the timer. If you didn't stop the timer at the end of the tick event it would continue to minimize and hide the form (even if it is hidden) every 3 seconds.

I hope this is what you were wanting to do.

:)
Was This Post Helpful? 1
  • +
  • -

#3 aristide  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 25-December 11

Re: [VB.NET] Form Auto-Opening And Closing Question

Posted 25 December 2011 - 12:40 PM

View PostMartyr2, on 25 December 2011 - 12:36 PM, said:

Here is the code which will minimize and hide the form after 3 seconds. Notice the button event will set the interval of the timer to 3000 milliseconds (3 secs) and at which time will kick off the tick event. At the end of the event we will stop the timer.

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Me.WindowState = FormWindowState.Minimized
        Me.Hide()
        Timer1.Stop()
    End Sub



Now the button to trigger this tick event. We use the start() method to start the timer...

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Interval = 3000
        Timer1.Start()
    End Sub



Set the interval, then start the timer. If you didn't stop the timer at the end of the tick event it would continue to minimize and hide the form (even if it is hidden) every 3 seconds.

I hope this is what you were wanting to do.

:)

Thanks for the information. But how can i do it that on the timer's tick the Form pops up and closes again after 3 seconds? Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 220
  • View blog
  • Posts: 1,478
  • Joined: 16-March 11

Re: [VB.NET] Form Auto-Opening And Closing Question

Posted 25 December 2011 - 02:44 PM

Under the click event enable the timer. Under the tick event of the timer, make the form hide. Simple as that, if you want it to show itself again then use a boolean. If the boolean is true hide and set to false, otherwise if the boolean is false show and set to true.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1