Dashed Line

J

JezB

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);
 
J

JezB

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

Jason Hales

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top