Problem setting the Character Style of a Shape

Jan 24, 2013 at 5:50 PM

I used the following code snippet to change the character style of a shape.  However, after applying the change, I found I was no longer able to move or resize the shape in the diagram.  If I comment out the shape.SetCaptionCharacterStyle function call, I was then able to move the shape.

var shape = (RectangleBase)project1.ShapeTypes["Ellipse"].CreateInstance();

CharacterStyle characterStyle = new CharacterStyle
{
   Size = 8, 
   ColorStyle = new ColorStyle("Black",Color.Black),
   FontName = "Tahoma",
   Style = FontStyle.Bold
};
shape.SetCaptionCharacterStyle(0, characterStyle);

Coordinator
Jan 25, 2013 at 8:13 AM

You have to insert your new character style into the project's design before using it:

CharacterStyle myCharacterStyle = new CharacterStyle
{
Name = "myCharacterStyle", // Setting a name is mandarory as you will need the name to address the style Size = 8, ColorStyle = new ColorStyle("Black",Color.Black), FontName = "Tahoma", Style = FontStyle.Bold };
project.Design.AddStyle(myCharacterStyle); // This will automatically create a transparent grayscale 'preview style' used for preview

// Insert the style into the repository so it will be saved/loaded
project.Repository.Insert(project.Design, myCharacterStyle);
var shape = (EllipseBase)project1.ShapeTypes["Ellipse"].CreateInstance();
shape.SetCaptionCharacterStyle(0, project.Design.CharacterStyles["myCharacterStyle"]);
Jan 25, 2013 at 2:34 PM

Thank for the quick response!  Appreciate your support.   Well written diagramming source code!