How to a make a label appear for only 3 seconds in VB.NET???

Posted on 2007-10-05
Last Modified: 2010-04-23
I am using VB.Net. Basically I want a label to appear for only 3 seconds in my code as it executes..

This is what I have...

 Dim timeOut As DateTime = Now.AddMilliseconds(3000) '3 seconds

        lbMsg3.Visible = True
                lbMsg3.Text = "INVALID TAG NUMBER"
                lbMsg3.ForeColor = Color.FromArgb(205, 38, 38)
            Loop Until Now < timeOut

            'after 3 seconds I want the message to disappear
            lbMsg3.Visible = False

This is the code I have for a label but I want it to disappear after 3 seconds of it displaying....but I don't see it first or last....I suspect it is skipping my DO Loop...

How I pause the application so that I see the lable for 3 seconds and have it disappear once 3 seconds have elapsed.

Any hep or insight would be much appreciated.
Question by:nomar2
    LVL 25

    Accepted Solution

    do a lblMsg3.refresh to be sure it displays and
    after that do

    This will freeze for 3 seconds (3000ms)


    LVL 25

    Expert Comment

    BTW, get rid of the DO loop if you use the sleep command as I don't think you'll need it.
    LVL 20

    Expert Comment

    Do you want the whole program to be frozen for those three seconds, or can the user do something else if he wants to?

    If you don't want to freeze, then you should use a Timer control:

        Friend WithEvents TimerDisplay As New System.Windows.Forms.Timer
        TimerDisplay.Interval = 3000
        TimerDisplay.Enabled = False

        Private Sub TimerDisplay_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles TimerDisplay.Tick
            TimerDisplay.Enabled = False                ' Don't display again
            Label1.Visible = False
        End Sub

    When you display the label, add:

        TimerDisplay.Enabled = True

    This will cause the timer to start counting. When 3 seconds are up, the Tick event will fire, and the label will disappear.
    LVL 20

    Expert Comment

    Sorry, I should have looked back at your code to use the right name for the label. Change the second line of the Tick event to:

          lbMsg3.Visible = False

    rather than "Label1".
    LVL 25

    Expert Comment

    If you don't want the program frozen, their are several ways to tackle the problem.
    You could use a separate thread or the BackgroundWorker component ( 2005) to do this.  Using a timer is just a way to use a cheap simple additional "thread"

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now