Trying to draw a dashed line within a User Control I get error:

Changes cannot be made to Pen because permissions are not valid

Why is this ??

Pen dashed = Pens.DarkGray;
dashed.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLine(dashed, 0, 100, 200, 100);

Re: Dashed Line by JezB

JezB
Mon Apr 10 03:51:42 CDT 2006

Well, I dunno about this restriction but I got round it by moving the code
into a static method in a library.

"JezB" <jezbroadsword@blueyonder.co.uk> wrote in message
news:O9JUrdHXGHA.1564@TK2MSFTNGP03.phx.gbl...
> Trying to draw a dashed line within a User Control I get error:
>
> Changes cannot be made to Pen because permissions are not valid
>
> Why is this ??
>
> Pen dashed = Pens.DarkGray;
> dashed.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
> g.DrawLine(dashed, 0, 100, 200, 100);
>



Re: Dashed Line by Jason

Jason
Tue Apr 11 05:44:41 CDT 2006

All of the those Pens are system defined pens which you shouldn't be
able to alter:

This would of worked - (by cloning DarkGray)

Pen dashed = Pens.DarkGray.Clone() as Pen;
dashed.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
g.DrawLine(dashed, 0, 100, 200, 100);

I'm surprised it work just by copying into a static method - any chance
you could share the code?