Utututu
Utututu

Reputation: 41

Can I do something more with Pen.DashPattern?

So, I start from creating Pen using only Color as argument.
What can I do with DashPattern other that assigning a float[]?

I've tried to check if it is null or not, using comparison operator.
Result: OutOfMemoryException.

Checking length of potentially existing allocation also failed - same exception.

Problem started from trying to transfer data from a row of float[,] to DashPattern of Pen using Buffer.BlockCopy().

Upvotes: 0

Views: 251

Answers (1)

Jimi
Jimi

Reputation: 32248

This behavior is by design.

If you haven't specified a DashStyle different from the default DashStyle.SolidColor or set the Pen.DashPattern to a float[] value, setting, as a consequence, the Pen.DashStyle to DashStyle.Custom, the Pen.DashPattern is not set and the native GdipGetPenDashCount method will return a Status != GDIP.Ok = 0.

The default behavior, when the dash count is not set, is to raise a GDI+ exception, an OutOfMemoryException in this case.

What you can do is to test the Pen DashStyle and try to get its DashPattern only when DashStyle != DashStyle.Solid (setting this style explicitly won't create a DashPattern):

if (pen.DashStyle != DashStyle.Solid)
{
    Console.WriteLine(pen.DashStyle);
    pen.DashPattern.ToList().ForEach(f => Console.WriteLine(f));
}

Upvotes: 2

Related Questions