index > Visual Studio Team System - Domain-Specific Language Tools > How to change the font of a shape?

How to change the font of a shape?


How can I change the font for 
  1-) whole shape
  2-) diagram
  3-) part of a shape (like only compartment items, or title)

Thanks.
Gokhan Ertas

Fonts are a bit of a tricky thing in the diagramming surface. First, there's no easy way to change the font for the whole diagram. You'll need to change things at an individual shape level.

You can change the font for all of the decorators on a shape (I've added the code for this below), but it's complicated by the fact that decorators are not ShapeFields, so you need to change the font information on each decorator. However, one of our planned changes is to convert inner decorators to ShapeFields, so that should fix this.

As for changing the parts of a compartment, you should be able to change the compartment header text and list item text fonts independently.



namespace CompanyName.ProjectName.TestLanguage.Designer
{
 #region Using directives

 using System;
 using System.Collections.Generic;
 using Microsoft.VisualStudio.Modeling;
 using System.Diagnostics;
 using Microsoft.VisualStudio.Modeling.Utilities;
 using System.Drawing;
 using Microsoft.VisualStudio.Modeling.Diagrams;

 #endregion

 /// <summary>
 /// ClassShape in the Class Diagram template.
 /// </summary>
 public partial class ClassShape
 {
  /// <summary>
  /// Gets called whenever a shape is inserted into the diagram.
  /// This is a good time to setup visuals, because all shapes,
  /// decorators, compartments, shapefields, etc. have been created.
  /// </summary>
  public override void OnShapeInserted()
  {
   base.OnShapeInserted();

   // Define the font change to make.
   // In this case, make all decorators show bold, italic,
   // and bigger sized text.
   FontSettings fs = new FontSettings();
   fs.Bold = true;
   fs.Italic = true;
   fs.Size = 0.185f;

   foreach (ShapeDecorator decorator in this.Decorators)
   {
    // Only do this for all of the text decorators in this shape.
    TextShapeDecorator shapeDec = decorator as TextShapeDecorator;
    if (shapeDec != null)
    {
     shapeDec.StyleSet.OverrideFont(DiagramFonts.ShapeText, fs);
    }
   }

   // Make the compartment header title bold, and
   // the compartment item test italic.
   FontSettings fsTitle = new FontSettings();
   fsTitle.Bold = true;
   FontSettings fsItem = new FontSettings();
   fsItem.Italic = true;

   foreach (ShapeElement shape in this.NestedChildShapes)
   {
    // Only do this for all of the compartments in this shape.
    Compartment compartment = shape as Compartment;
    if (compartment != null)
    {
     compartment.StyleSet.OverrideFont(DiagramFonts.ShapeTitle, fsTitle);
     compartment.StyleSet.OverrideFont(DiagramFonts.ShapeText, fsItem);
    }
   }
  }
 }
}

 



The code above should produce compartments with bold headers and italic item text. However, due to a bug both are italic. I've entered a bug against that, so that we can fix it, so that both are independent.




Pedro Silva - http://blogs.msdn.com/pedrosilva
Pedro Silva
Hmm, the formatting for this code came out a little weird...


Pedro Silva - http://blogs.msdn.com/pedrosilva
Pedro Silva
reply 3

You can use google to search for other answers

 

More Articles

DSL Tools available for Beta2??
"DSL DM -> DD" for November 2005 CTP is available (c...
How adequate-rich or suffitient-complete the DSL?
Show or Hide icon decorator at runtime
Jochen Seemann's presentation on PDC05
Overriding custom attribute in a derived class
Create a diagram by using custom code
"Static" Swimlanes
DSL Tools Sept CTP and WinFX Sept CTP?
Prevent rules from firing during model deserialization
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

Show or Hide icon decorator at runtime
Open a new Document
Add shapes and connectors to diagram pro…
Tying domain classes to shape objects
DSL Tools November CTP and VS SDK Decemb…
Error with DSL Project Setup
Troubleshooting: duplicate generated files
Multiplicity Value Property
Keeping separate models in step
Unable to Replace Old Files by New ones
Problem running Debug solution
Is there any documentation regarding the…
How to Prevent property from being displ…
Validation / Rejecting a change from a C…
Beginners Question on code generation

Hot Articles

Supported VGRoutingStyles?
Compartment Shape Equivalents
ROM for developing a Use Case cartoon in…
Experimental UI - show and hide shapes a…
How adequate-rich or suffitient-complete…
How to determine if a model passes valid…
Unable to intercept double click on deco…
Controlling Font
Shape inside a shape
Problem with the VS SDK March 2006
Inheritance Restriction?
DSL Setup project fails to compile
Is there documentation for the T4 engine…
Split (T4) code in more than 1 text temp…
Fixed diagram layout

Recommend Articles

How to expose domain model objects throu…
Retrieving embedded elements
Problem installing latest DSL toolkit ...
Customize DirectiveProcessor
Change name of Extension & name of t…
DSL Tools outside VS?
fatal error CTC2013: Can't start preproc…
Is there someone on the DSL tools team I…
use case template dropped?
Problem Installing DSL Tools September 2…
Save instance of model in menu command
Reflecting domain property value on shap…
Getting validation results
Join the World's Largest User Group on S…
bidirectional connectors