LED Control
HomePage | Contact | Resume| Client List | EngineeringLinks | Embedded | Forum

LED Display Indicator Control
Written by: Michael Karas

There have been numerous times that I wanted to include one or more LED indicators on to a Visual Basic form. Several times I followed the suggestions like given in on-line forums such as www.xtremevbtalk.com where it is suggested that LED indicators can be easily be simulated through the use of two images on a usercontrol or picture box. Then it is suggested that you simply make one visible and the other not, depending on which state you want the LED to be in.

I have found however that this type of implementation is often not quite right for the applications that I had at hand. So I set out to make my own LED control with part of the intention being to learn how ActiveX controls are produced in Visual Basic. This web page includes a download link for the ZIP file containing the source code for the LED control that I produced. I had fun making it and hope that other readers may find it useful either as an LED control in your own programs or as a template for starting your own ActiveX control or user control development. The code available here has the control implemented as a User Control. This allows for easy code development and testing. It is not a difficult task to transform the user control into a full blown ActiveX control should this be required in your project.

The control is an LED indicator control that can be placed on a form to simulate an actual LED. The display indicator is painted as a round image using direct drawing commands instead of the more common LED implementations using bitmap images. The indicator image includes a 3D border and a reflection glint to give the appearance of realism to the control. The two inages below show some screen shot snippets of the LED control. The first picture shows some of the various sizes that can be attained. The next picture also shows some size variations and also shows the four LED colors in both the off and on states.


Through the use of the graphic drawing algorithm used in the control, the LED can be set to almost any practical size at design time from a few pixels across to a few hundred pixels, although the realism look of the indicator starts to degrade after the control is sized over about 50 pixels. (The ability to size the LED was a key motivator to design and build this control as other sample controls from the WEB are fixed size and many times too small for display screens with a high density pixels/inch setting).

The image below shows the Visual Basic properties box for the LED control. Four specialized property settings, all of which are read/write at both design time and run time, provide the ability to customize the control to specific usages.

The following list describes these properties in detail:
  • LED.State As Boolean - Controls the LED On/Off state. True = On while False = Off. (Note that this state is a higher state over the Blink states on/off that flashes the image).

  • LED.Blink As Boolean - This controls whether the LED will blink when it is in the On state. An LED can have its blink state set on even though the LED may be actually off via the State property. True = Blink enabled while False = no blink.

  • LED.Interval As Integer - This property specifies the blink rate interval for the LED in nominal units of milliseconds. Note that this property value is utilized directly by a standard timer and as such has similar granualrity and resolution behavior that a normal timer control will have. Practical values for the interval parameter are from 50 to 1000. At 1000 the LED blinks off for 1 second and then on for 1 second.

  • LED.Color As LEDColorSelection - This property specifies the color for the LED. The values are specified by a Public enumeration value in the control. The selection values are:
    1. LED_Red
    2. LED_Green
    3. LED_Yellow
    4. LED_Blue

The control comes packaged with a simple test application program that permits the LED control behavior to be manipulated and studied. The picture below shows what this test application looks like:

Click the link below to download the LED Control source code and project files that have been packed into a ZIP archive file.

Download LED Control

(Note regarding the download: You may incorporate all or parts of this program into your own project. Keep in mind that you get this code free and as such Carousel Design Solutions has no responsibility to you, your customers, or anyone else regarding the use of this program code. No support or warranty of any kind can be provided. All liability falls upon the user of this code and thus you must judge the suitability of this code to your application and usage).

Email:  mkaras@carousel-design.com
Web Site:  www.carousel-design.com