Timer Question

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I have a Yellow text box on a winform that normally stays hidden but on
occasion I make it visible to display some message to the user. In one
particular case it would be nice if the text box would only stay visible for
a few seconds. Is this possible? If so I suppose it involves a Timer
control but it is not clear to me how to program the Winform so that the
textbox stays visible only for a given period of time. If is is visible for
say only two seconds, would all other processing have to stop for two
seconds too?
 
Hi,


Here is a simple-minded example that turns a textbox visible, and not
visible, using a timer, at 2-second intervals. You should be able to modify
it to do what you really want with no trouble. Just add a TextBox and Timer
to a Windows Forms project to give it a try.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Static Visible As Boolean

TextBox1.Visible = Not (Visible)

Visible = TextBox1.Visible

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

With Timer1

Timer1.Interval = 2000

Timer1.Enabled = True

End With

End Sub

End Class


--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
* "Woody Splawn said:
I have a Yellow text box on a winform that normally stays hidden but on
occasion I make it visible to display some message to the user. In one
particular case it would be nice if the text box would only stay visible for
a few seconds. Is this possible? If so I suppose it involves a Timer
control but it is not clear to me how to program the Winform so that the
textbox stays visible only for a given period of time. If is is visible for
say only two seconds, would all other processing have to stop for two
seconds too?

No, the Windows Forms Timer control doesn't block the execution.
 
Hi Woody,

The timer will raise Tick event after an internal(you can specify), so you
can handle certain operations in this event handler.
And it will not block the execute of other controls.

For you issue, you can do like this:
'First, you should have placed a timer control on to the form.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Visible = False
End Sub

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

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
TextBox1.Visible = False
End Sub

Hope this helps,

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "Woody Splawn" <[email protected]>
| Subject: Timer Question
| Date: Mon, 20 Oct 2003 11:20:23 -0700
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.vb
| NNTP-Posting-Host: 168.158-60-66-fuji-dsl.static.surewest.net
66.60.158.168
| Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:148442
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
|
| I have a Yellow text box on a winform that normally stays hidden but on
| occasion I make it visible to display some message to the user. In one
| particular case it would be nice if the text box would only stay visible
for
| a few seconds. Is this possible? If so I suppose it involves a Timer
| control but it is not clear to me how to program the Winform so that the
| textbox stays visible only for a given period of time. If is is visible
for
| say only two seconds, would all other processing have to stop for two
| seconds too?
|
|
|
|
|
|
 
Back
Top