.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

  • Today's competitive marketplace requires the organization to frequently release and deploy applications at the pace of user demands, with reduced cost, risk, and increased quality. This book defines the basics of application release and deployment, and provides best practices for implementation with resources for a deeper dive. Inside you will find: The business and technical drivers behind automated application release and deployment. Evaluation guides for application release and deployment solutions. …

  • Hurricane Sandy was one of the most destructive natural disasters that the United States has ever experienced. Read this success story to learn how Datto protected its partners and their customers with proactive business continuity planning, heroic employee efforts, and the right mix of technology and support. With storm surges over 12 feet, winds that exceeded 90 mph, and a diameter spanning more than 900 miles, Sandy resulted in power outages to approximately 7.5 million people, and caused an estimated $50 …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds