.NET LED Control in C#

Environment: Written in C# and Windows Forms for .NET. Compiled using VS7 (7.0.9466) and tested using Windows 2000 with the .NET Framework (1.0.3705)

I've found the Static LED Control contributed by Monte Variakojis for Win32 (MFC and C++) to be very useful and have employed it in many small projects. As a learning exercise, I ported his control moving it forward to .NET. This implementation uses C# and Windows Forms. The 16x16 pixel LED bitmap is the original.

If I've implemented the control faithfully, the implementations can be compared and contrasted to evaluate aspects of the new .NET technology. The original is at http://www.codeguru.com/controls/StaticLed.shtml

The LEDs are drawn in a PictureBox image-related Windows Forms control. The PictureBoxLED class inherits from the PictureBox control and overrides its OnPaint message to write the bitmap onto the MessageBox surface. The PictureBoxLED also implements the IBitmapLED interface as does the actual LED (PictureBoxLED16x16). This intermediate stage (PictureBoxLED) could be used to make instances of other sized bitmaps (a Bridge Pattern separating the interface from the implementation). I did substitute a "blink" method, which I find more useful, in place of the "Ping" method in the original.

The bitmap can be loaded from an external file (called "leds.bmp") or from the internal resource (selected by the LOADFROMRESOURCE define). This is done at the top (FORM) level and the source image is passed all the way down to the drawing component.

Implementation:

Using the LEDs are very simple. In VS.NET, drag a WindowBox from the toolbox onto the design form. Display the properties, change the WindowBox size to 16x16. This is not strictly required as the program will do it but helps with the visual alignment. Use the WindowBox name provided or provide a new one to one of the constructors for PictureBoxLED(). Remember the "*.Parent = this" to hook up the child control for messages. "Using" the PictureBoxLED16x16 and PictureBoxLEDS namespaces.

Operations:

Should operate as the original with a blink method replacing the "Ping" method. See the embedded XML.

Downloads

Download demo project: LedDemo.zip - 44 Kb


Comments

  • An LED for .NET

    Posted by Legacy on 08/03/2003 12:00am

    Originally posted by: Seth Olitzky

    I have implemented an LED that can be used at design time in Visual Studio 2003. Go to the following page to download the .DLL file. www.broadcastsoftware.biz/download.html

    Reply
  • LED as a Visual Component in Toolbox

    Posted by Legacy on 06/14/2003 12:00am

    Originally posted by: Seth Olitzky

    It might be nice if someone could convert this to a visual component that could be added directly to the Toolbox palette so that an LED could just be dropped onto a form without having to write any code to connect the LED to a Windows Box.

    Reply
  • 44K zip takes 10MB to run !

    Posted by Legacy on 12/01/2002 12:00am

    Originally posted by: andy burns

    This is the first C# program I've knowingly run, I'm not trying to criticise the author dor slack programming ;-)

    Presumably the 10MB of memory used are runtime is the cost of using the CLR?

    Reply
  • LED BUTTON !

    Posted by Legacy on 05/14/2002 12:00am

    Originally posted by: Paresh Gheewala

    It was a nice example. Looks like same as starting the MS-SQL server. Infact we can create the buttons of these led colors and give the user an interactive option using C# windows and forms and controls overloading...

    Thanks a lot
    Paresh

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: March 27, 2014 Teams need to deliver quality software faster and need integrated agile planning, task tracking, source control, auto deploy with continuous builds and a configurable process to adapt to the way you work. Rational Team Concert and DevOps Services (JazzHub) have everything you need to build great software, integrated seamlessly together right out of the box or available immediately in the cloud. And with the Rational Team Concert Client, you can connect your …

  • By providing complete access control with granular permissions, deployment flexibility, mapped drive support, and ability to transfer large files, Egnyte provides a more robust, secure and an affordable file sharing solution for the business than Box

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds