.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: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • On-demand Event Event Date: October 29, 2014 It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this webcast, Gene Kim discusses these survey findings and shares woeful tales of artifact management gone wrong! Gene also shares examples of how high-performing DevOps …

Most Popular Programming Stories

More for Developers

RSS Feeds