Pen Permissions

Inside of a Link type that I created I am doing the following code:

this.Pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;

This causes an exception: “Changes cannot be made to Pen because permissions are not valid”

Why is this?

Anyone know?

From the User Guide:

You will typically set the GoShape.BrushColor, BrushStyle, and BrushForeColor properties to fill the shape with the brush that you want. Similarly, you can set the GoShape.PenColor and PenWidth properties to control the most commonly set Pen properties. But you can also construct your own Pen and Brush values. This is useful when you want a dotted pen, or a texture or gradient brush. Be sure to finish setting them up the way you want before you set the GoShape.Pen or GoShape.Brush properties, because you may not change a Pen or Brush after you have assigned it as a property value.

Ok, I read that, but why does this not work based on that? And since it seems to not work, how do you take a link and make it dashed?

Pen p = Pens.Black;
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
this.Pen = p;

“this” is an instance of GoLink.

Pens.Black is a system pen, you can’t modify it.

The limitation of not being allowed to modify Pens or Brushes once they are “in-use” is one that GDI+ imposes.

So you need to create a new Pen or a new Brush, initialize it the way you want, and then assign the property.

We do a lot of that work for you in version 3.0, where there are separate properties and we automatically construct new Pens or Brushes when needed. (It was also needed to implement work-arounds for various limitations and bugs in GDI+.) The goal was to greatly reduce the use of Pens and Brushes in code using GoDiagram.

However, there isn’t any GoShape.PenDashStyle property. We considered adding something like that for v3.0, but didn’t think it was used frequently enough.

If we do add such a property, we’d probably generalize it to be GoShape.PenDashPattern, an array of single-floats, rather than the limited enum values defined by System.Drawing.Drawing2D.DashStyle.