This project has moved and is read-only. For the latest updates, please go here.

Forcing shape redraw after model property updated

Oct 19, 2012 at 8:44 AM


In my case the "Text" property is not enough for my custom shapes: the text drawn on the shape depends upon several properties of the model assigned to this shape. To draw this text, I override the Draw() method of my shapes, for example:

public override void Draw(Graphics graphics)
    ProcessorModel pm = this.ModelObject as ProcessorModel;
    if (pm != null)
        graphics.DrawString(string.Format("Type: {0}\r\nName: {1}", pm.ProcessorType, pm.Name),
            DrawingToolsCache.GetFont(this.CharacterStyle.FontFamily.Name, this.CharacterStyle.SizeInPoints),

When I change property Name (or ProcessorType) in the model, shape is not updated (redrawn) immediately. To redraw the shape, I must move focus away from the model's PropertyGrid (e.g. by clicking on the Diagram's area).

How can I achieve immediate redraw?!

Oct 19, 2012 at 9:16 AM

I found the solution:

public override void NotifyModelChanged(int modelPropertyId)

Oct 19, 2012 at 9:32 AM

Call shape.InvalidateDrawCache() followed by shape.Invalidate(). 

Did you notice the Caption class? It handles most of the drawing/transforming stuff. It's method names are equivalent to the shape's method names in order to make it clear where to call which method. Have a look at the EntitySymbol shape in the SoftwareArchitectureShapes. This shape uses multiple captions, too.

Oct 19, 2012 at 10:29 AM

Thank you for the advice! However, for my purposes it will be enough to override the Draw() method. My shapes are not rotatable, so there's nothing difficult here - just a call to Graphics.DrawString().