|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionIn my previous article , I created an analog meter with a custom renderer. Now I thought to add more controls to the library in order to be able to use it for the creation of forms to control a process or for other various reasons. To compile this demo you need .NET 2.0. which is available here. The project is developed with SharpDevelop, a free IDE per .NET. Controls DecriptionIn this version of the library, I include these types of control:
All controls are derived from Library NamespacesLBSoft.IndustrialCtrls.Leds
In this namesapace there are the controls that simulate a led for the visualization of a state. At the moment, there is only the class Led Properties
There are two properties that are not visible at the design time, and are:
LBSoft.IndustrialCtrls.Meters
In this namesapace there are the controls that simulate a meters (analog or digital) to view a value. At the moment, there is only the class Analog Meter Properties
There are two properties that are not visible at the design time, and are:
The class
This is an example that how to set the thresold in the meters controls: ...
public void SetThresholds()
{
LBMeterThreshold threshold = new LBMeterThreshold();
threshold.Color = Color.Yellow;
threshold.StartValue = 50;
threshold.EndValue = 70;
this.lbAnalogMeter1.Thresholds.Add ( threshold );
threshold = new LBMeterThreshold();
threshold.Color = Color.Red;
threshold.StartValue = 70;
threshold.EndValue = 100;
this.lbAnalogMeter1.Thresholds.Add ( threshold );
}
...
LBSoft.IndustrialCtrls.Buttons
In this namesapace there are the controls that simulate the button to send a command. At the moment, there is only the class Button properties:
Like the previous controls there are properties that are not visible at the design time:
EventsThis control, when the state change, fire up an event to inform the connected class. This event is:
The property LBSoft.IndustrialCtrls.Knobs
In this namesapace there are the controls that simulate knobs to change a value (like a slider). At the moment, there is only the class Knob Properties
Like the previous controls there are properties that are not visible at the design time:
EventsThis control, when the state changes, fires up an event to inform the connected class. This event is:
The property LBSoft.IndustrialCtrls.UtilsIn this namespace there are two class with only static members for common use:
Renderers DescriptionNow is the time to explain how to create the custom renderers. Any control, has a base renderer class, and any renderer class has a property to set the control. All the methods in the renderer class are virtual and if you want to change the aspect of the control, is possible to override one or all methods. The renderers available for the controls are:
To create a custom renderer, you following these steps:
namespace TestApp
{
///
/// Class for custom renderer
///
public class LBCustomLedRenderer : LBLedRenderer
{
///
/// Draw a rectangular led
///
public virtual bool DrawLed( Graphics Gr, RectangleF rc )
{
if ( this.Led == null )
return false;
Color c = this.Led.LedColor;
SolidBrush br = new SolidBrush ( c );
Pen pen = new Pen ( c );
Gr.DrawRectangle ( pen, rc );
Gr.FillRectangle ( br, rc );
br.Dispose();
pen.Dispose();
return true;
}
}
public partial class MainForm : Form
{
private LBCustomLedRenderer myRenderer = null;
public MainForm()
{
InitializeComponent();
this.myRenderer = new LBCustomLedRenderer();
this.lbLed1.Renderer = this.myRenderer;
}
...
}
}
ConclusionThis is the initial version of the library, many features have yet to be implemented, and I hope to do so soon. Any suggestions/comments/feedback are highly appreciated, because I only started using C# 2 weeks ago, and I don't know if the code that I wrote is the best way to do things. For this article, I used the code and the ideas of these articles :History
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||