.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

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • The mobile market is white hot. Building a well-crafted product development plan that addresses market research, strategy, design, and development will provide the greatest chance for success. Each phase of an app's lifecycle is critical to the its overall success and feeds into the next step of the process of product development for the app. This white paper examines the five key phases of mobile app creation, one by one, to understand how they work together to help create a successful mobile app.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date