11-25-2011 01:55 AM
Hello,
in my application I want to save the settings of an annotation. When I use the annotation.ShapeStyle.ToString() method it only delivers "ShapeStyle". I think
they should give back the name of the actual shape, to use the Shape.Parse() function to get the saved condition.
Best regards
Gerald
Solved! Go to Solution.
11-28-2011 09:16 AM
Hi Gerald,
in which relation do you use the annotation? I assume you would like to save the specific comments for the program. Are you using therefore any specific NI libary like NI VISA Class Libary, NI DAQ, or NI Windows?
In which libary is the command annotation.ShapeStyle.Tostring() command included?
Thanks
Rupert
11-29-2011 01:28 AM
Hi Rupert
they are all in the Nationalinstruments.UI.dll.
here is an codesample
XYPointAnnotation annotation = new XYPointAnnotation(scatterGraph1.XAxes[0], scatterGraph1.YAxes[0], 1, 1); annotation.ShapeStyle = ShapeStyle.Diamond; scatterGraph1.Annotations.Add(annotation); //Save the setting in a String string saveString = annotation.ShapeStyle.ToString(); //Load the Settings annotation.ShapeStyle = (ShapeStyle)ShapeStyle.Parse(typeof(ShapeStyle), saveString);
Regards Gerald
11-29-2011 03:52 AM
Hi Gerald,
thanks for the sourcecode - now I am aware what's your aim. I could reproduce the issue about the annotation.ShapeStyle.ToString() -
it doesn't deliver the current shape of the marker.
You can use annotation.ShapeStyle.GetType().ToString(), this method allows you to get back the current shape in this order Class+CurrentStyle.
Best regards,
Rupert
11-29-2011 04:28 AM
Ok i tried this and I get the follwoing string:
"NationalInstruments.UI.ShapeStyle+DiamondShapeSytleImpl".
In which way can I now restaurate this value. My aim is, to save the settings of the annotation in a file. So I save this string. But when I load the file what shall I do whith this string?
Regards Gerald
11-29-2011 04:48 PM
Hi there,
Unfortunately, the ShapeStyle does not provide a way to preserve its properties to a file and load it back when needed. You will have to write your own APIs to do serialize and deserialize them to/from file.
I would suggest preserving properties in XML format is the best way to do it. When parsing the XML, get the values of the properties (that is, converting strings to appropriate types). And, use the ShapeStyle.Create...(..) methods to create a shape style.
Regards,
Vijet Patankar
National Instruments
11-30-2011 12:46 AM
Hi,
thats what I want to do. I want to save the Properties in an XML file. Here a codesample:
XYPointAnnotation annotation = new XYPointAnnotation(scatterGraph1.XAxes[0], scatterGraph1.YAxes[0], 1, 1); annotation.ShapeStyle = ShapeStyle.Diamond; scatterGraph1.Annotations.Add(annotation); //the Funktion for the save-method -> don't work string saveShapeStyleString = annotation.ShapeStyle.ToString(); //the Funktion for the load-method annotation.ShapeStyle = (ShapeStyle)ShapeStyle.Parse(typeof(ShapeStyle), saveShapeStyleString); //the Funktion for the save-method -> works string saveArrowHeadStyleString = annotation.ArrowHeadStyle.ToString(); //the Funktion for the load-method annotation.ArrowHeadStyle = (ArrowStyle)ShapeStyle.Parse(typeof(ArrowStyle), saveArrowHeadStyleString);
the ShapeStyle .ToString() Method always deliver "ShapeStyle". According to this the ArrowHeadStyle.ToString() delivers the actual value e.g. "EmptySquare". I think it's a Bug in the dll.
Regards Gerald
11-30-2011 11:44 AM
Hello there,
You are quite right for the fact that the ShapeStyle returns the "ShapeStyle" string for different shapes.
Note: ShapeStyle and ArrowStyle are not related in the class hiararchy. ArrowStyle is not a sub-class of ShapeStyle (and vice versa).
For your use case you could create a method that would check the shape style and return you the correct string.
Something like the following,
public string GetStyleName(Object style)
{
if(style is ShapeStyle)
{
if(style == ShapeStyle.None)
{
return "None";
}
else if(style == ShapeStyle.Oval)
{
return "Oval";
}
.
.
.
}
else if(style is ArrowStyle)
{
return style.ToString();
}
}
For loading you could create a (factory) method to actually compare the strings and return the a value.
public Object GetMyStyleByName(string name, Type type)
{
if(type == typeof(ShapeStyle))
{
if(name == "None")
{
return ShapeStyle.None;
}
.
.
.
}
}
Hope this helps.
Regards
Vijet Patankar
National Instruments
12-01-2011 12:34 AM
Hello,
thank you for your answer. I will take your example as solution for the problem.
Best regards
Gerald