.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

  • For the third consecutive year, Neustar surveyed hundreds of companies on distributed denial of service (DDoS) attacks. Neustar's survey reveals evidence that the DDoS attack landscape is changing. The number of companies attacked is up, but attack duration is down. Larger attacks are more common, but most attacks are still less than 1 Gbps. More than half of attacked companies reported theft of funds, data or intellectual property. Read the full report to learn how DDoS attacks have evolved in both strategy …

  • Live Webinar Tuesday, August 26, 2014 1:00 PM EDT Customers are more empowered and connected than ever, and the customer's journey has grown more complex. Their expectations are growing and trust is diminishing as they may interact with multiple brands through web, mobile and social channels. Considering 70% of the buying process in a complex sale is already complete before prospects are willing to engage with a live salesperson -- it's critical to understand your customers and anticipate their needs.* …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds