07-09-2010 11:26 PM
I am trying to restore some functionality to LED's which is not present in Measurement Studio for Visual Studio 2008 (e.g., "on-text" and off-text"). However, in order to properly re-draw the controls I need to determine the LED style type. Any help you can give is gratefully accepted.
Thanks!
07-12-2010 01:52 PM
Hi Steverino,
You should be able to get and set the visual style of the LED by accessing the LedStyle property. If you are planning on re-drawing the control based on initial LED style, you may be able to implement if statements in your code as necessary.
For example,
If Led1.LedStyle Is LedStyle.Round3D Then
<yourCodeHere>
End If
I hope this helps!
07-12-2010 09:07 PM
What you are saying is true unless you customize the standard LedStyle. For example, if you change the color using the LedStyle property, even if the actual button type is the same, e.g., Square3D, the LedStyle is different. Still haven't figured out how to get the actual Led type (i.e, Round, Round3d, etc.).
07-13-2010 02:16 AM
If I have understood your question correctly, what you are trying to do is,
1. Create a custom LED Style type (say MyStyle) with additional properties.
2. Identify the LED Style type based on values of the properties of the MyStyle instance.
If it is so, this is what I would do.
public class MyStyle : LedStyle
{
public MyStyle()
{
}
public MyStyle(Color color, bool textOnValue)
{
ellipseColor = color;
textOn = textOnValue;
}
private bool textOn = false;
public Boolean TextOn
{
get
{
return textOn;
}
set
{
textOn = value;
}
}
private Color ellipseColor;
public Color EllipseColor
{
get
{
return ellipseColor;
}
set
{
ellipseColor = value;
}
}
public override void Draw(object context, LedStyleDrawArgs args)
{
LedStyle.Round3D.Draw(context, args);
// Some drawing code here.
// I am simply drawing an circle around the LED and
// draw 'hello' string if TextOn is true.
args.Graphics.DrawEllipse(new Pen(ellipseColor, 2), args.Bounds);
if (TextOn)
{
args.Graphics.DrawString("Hello", SystemFonts.DefaultFont, Brushes.Brown, new PointF(5, 5));
}
}
/////////////////////////////////////////////////////////////////////////////
// Solution 1
// The measurement studio provides 4 LED styles. You can customize it to have more LED Styles.
// If your requirement is to have a very small set of variations of properties, then you can create static instances of the custom LED style. Following are some sample static properties.
// NOTE: For this to work, the properties TextOn and EllipseColor should be GET only.
/////////////////////////////////////////////////////////////////////////////
public static readonly MyStyle myBlueColoredEllipseWithTextOff = new MyStyle(Color.Blue, true);
public static MyStyle MyBlueColoredEllipseWithTextOff
{
get
{
return myBlueColoredEllipseWithTextOff;
}
}
public static readonly MyStyle myRedColoredEllipseWithTextOn = new MyStyle(Color.Red, false);
public static MyStyle MyRedColoredEllipseWithTextOn
{
get
{
return myRedColoredEllipseWithTextOn;
}
}
/// Comparison of the style yet remains the same as follows.
/// if(myLedInstance.LedStyle == MyStyle.MyRedColoredEllipseWithTextOn)
/// {
/// //do something here.
/// }
/////////////////////////////////////////////////////////////////////////////
// Solution 2
// If the properties are both GET and SET types then you should consider this option.
/////////////////////////////////////////////////////////////////////////////
public override int GetHashCode()
{
int returnValue = 0;
//<ADD CODE HERE TO GET A UNIQUE HASHCODE FOR AN INSTANCE.
// THE HASH CODE CALCULATION SHOULD DEPEND ON THE NEW PROPERITES THAT YOU ADD.>
// So when you want to compare the instances, you just need to get the HashCode and compare the values.
return returnValue;
}
/////////////////////////////////////////////////////////////////////////////
// Solution 3
// This is another alternative if Hash code calculation isn't going to be easy.
/////////////////////////////////////////////////////////////////////////////
public string GetInstanceAsString()
{
StringBuilder returnString = new StringBuilder();
returnString.Append("TextOn: " + TextOn.ToArgb());
returnString.Append(", ");
returnString.Append("EllipseColor: " + EllipseColor.ToArgb());
// Use this string to compare.
return returnString.ToString();
}
/////////////////////////////////////////////////////////////////////////////
}
I hope this is what you are looking for. Let us know if you wanted something else.
Vijet Patankar
National Instruments.
//
07-13-2010 08:34 AM
Maybe I don't fully understand what I am asking for, and I probably don't fully understand your code as I am pretty much strictly a VB guy.
However, in your code in the overridden function Draw there is a parameter that defines the shape: e.g., LedStyle.Round3D.Draw. Obviously, if the LED I want to modify is a round 3d led this works. What if it is a square led? Then my function needs to be LedStyle.Square.Draw.
In other words, do I need to know before hand based on visual appearance or design what the shape of the LED is before I modify the style, and have style modifiers specific to the shape, i.e., one for Round3D, one for Square3d, etc.?
Thanks!
07-14-2010 01:49 AM
Hi there,
LedStyle just defines the shape of the LED control. By shape I mean, how the LED looks, whether it looks round, looks square or looks 3D or something else. The shape is drawn with different modifiers (like foreground color, background color). Note that these modifiers are the properties of the Led control class, not the LedStyle class. For example, the OnColor and OffColor properties are present on the Led class, and styles use these properties to draw thier shapes.
To give a better idea, lets say we want to draw Led in a shape of Polygon with n edges and has colored border for the shape.
What we should do is
> Derive from Led control (say PolygonShapedLed) and add two new properties BorderColor and NoOfEdges.
> Derive a custom Led Style (say PolygonShape) from LedStyle. Override the Draw() method and write the draw logic for the polygon. The nice thing about this is when you change the BorderColor or NoOfEdges on the Control, the Control is drawn with new settings.
So, if you have features (e.g. number of edges, or color of the border) that can have different values and govern the drawing, move them to the Control class rather than having them in style class.
If you have tried this out already and you have differnt issue altogether, then please detail out what you are trying to do. If you let us know what the requirements are (with code snippets if possible) we would be able to help you effectively.
Vijet Patankar
National Instruments
07-17-2010 06:09 PM
I have a form with a bunch of LED's on it. Some are round, and are used primarily (but not exclusively) as indicators. Some are square, and are used primarily as buttons. I would like to use several colors and text to indicate changing states. I would like to be able to pass the control (i.e., led) to a function, along with some parameters (e.g., color, text), and have the LED re-drawn. I am beginning to think I will need at least two functions - one for round and one for square leds. Correct?
The question I have been asking is this...if I pass the control to the function (be it round or square) without telling the function what shape I want to use when re-drawing the control, is there a property of the control that contains the shape property?