Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - Forms, Controls, and Other Useful Objects
Iron Speed
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Forms, Controls, and Other Useful Objects
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2007-02-08

    Table of Contents:
  • Forms, Controls, and Other Useful Objects
  • 4.2 Iterating Through All Controls on a Form
  • 4.3 Sharing Event-Handler Logic Among Many Controls
  • 4.4 Working with Timers
  • 4.5 Determining If a Control Can Take the Focus

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Forms, Controls, and Other Useful Objects - 4.4 Working with Timers
    (Page 4 of 5 )

    Problem

    You need to have some action occur on a regular basis in your form.

    Solution

    Sample code folder: Chapter 04\ClockTimer

    Use aTimercontrol, and set it for the desired interval. Create a new Windows Forms application, and add aLabelcontrol namedCurrentTimeto the form. Also add aTimercontrol to the form, and name itClockTimer. Set itsIntervalproperty to1000, and set itsEnabled property toTrue. Then add the following source code to the form’s code template:

      Private Sub ClockTimer_Tick(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles ClockTimer.Tick
         CurrentTime.Text = Now.ToLongTimeString
      End Sub

    When you run the program, that label updates once each second with the current time.

    Discussion

    The Timer control’sIntervalproperty sets the time betweenTickevents in milliseconds (1,000 per second). Although you can set theIntervalas low as one millisecond, the timer’s resolution is limited by your system’s hardware and operating-system-level factors.

    TheTickevent fires at approximately the interval you specify, if nothing more important is going on. If the code within yourTickevent handler is still running when the nextTickevent should occur, that subsequentTick event is disposed without a call to the event handler.

    See Also

    Recipe 14.8 shows how to have a section of code sleep, or take a small break. Some older Visual Basic code used timers for this purpose, although a timer is not the best solution in this case.

    More Visual Basic.NET Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Visual Basic 2005 Cookbook," published by...
     

    Buy this book now. This article is excerpted from chapter four of the Visual Basic 2005 Cookbook, written by Tim Patrick and John Clark Craig (O'Reilly; ISBN: 0596101775). Check it out today at your favorite bookstore. Buy this book now.

    VISUAL BASIC.NET ARTICLES

    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway