Scaled Pen DashStyle

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

It appears that the DashStyle of a Pen object is not
effected by the scale transform like the pen's width is.
Is this true and if so is this an oversight? How do I
scale the existing DashStyles?

Thanks!
Bob

Pen pen = new Pen(Color.Red, 1.0f);
pen.DashStyle = DashStyle.Dash;
pen.ScaleTransform(0.1f, 0.1f);
 
Hi Bob:
Do you mean that you want to use ScaleTransform to scale the pen?
Basically I guess you may want use the pen to display a line like the
following way:
--- --- --- --- --- --- --- ( before scale)
----- ----- ----- ----- ----- ( after scale)
-- -- -- -- -- -- -- -- -- ( another after scale)
Did I understand your problem correctly( you want the dash line to be
longer or shorter after scaled) ?


Best regards,

Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
 
No not correct. My problem appears to be a bug or
something else I need to do. I would think that the
DashStyle would be effected by pen.ScaleTransform.

If I scale the graphics with TransformScale as below and
then attempt to draw a dashed line, the line appears
solid. It is like the DashStyle line and space length is
not correct for the transformed coordinates. If I do a
custom DashStyle with a length and space of 0.05, it looks
OK.

Does this help clearify?

float scaleTransformX = 4f / (float)
this.ClientRectangle.Width;
float scaleTransformY = 4f / (float)
this.ClientRectangle.Height;
gfx.ScaleTransform(1.0f / scaleTransformX, 1.0f /
scaleTransformY);

pen = new Pen(GetColor(colorIndex), 2f);
pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
pen.ScaleTransform(scaleTransformX, scaleTransformY);
gfx.DrawLines(pen, nodeF5Points);
 
Hi Bob:
Because you zoomed in the Dashstyle line into a large size, almost 226
times, the solid line you see is a part of the dash line. It is like that
you use the microscope to observe a dash line, what you can see is the part
of the line. If you could see the whole scene, you will find a dash line
not a solid line.
As you said before, you can use custom DashStyle with a specific length
and space to show the large line's DashStyle in a small area.


Best regards,

Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
 
Yes I am aware that I could create a custom DashStyle but
if Pen.TransformScale effects the line width, it should
also effect the DashStyles. What use are the default
DashStyles if you transform the Graphics? I still think
it is a bug.

Thanks!
Bob
 
Hi Bob:
I think that it depends on how you understand it. Both
pen.ScaleTransform and graphics.ScaleTransform can affect lines drawn with
the pen. The pen.ScaleTransform affects the pen, but the Graphics objects
are associated with a specific device context, so graphics.ScaleTransform
affects a large area.
Imagine that you are drawing a picture on a resizable board, you can
draw a line with many different pens, and because the board is resizable,
you can also zoom in/out of the picture as you like. In a small area of the
board, it makes no difference whether you use a pen or zoom in/out the
board. While using them, you can feel that they are different, but equally
useful.


Best regards,

Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
 
Back
Top