Exploring GDI+ : Using the Pen

In my tour in exploring GDI+ I explored the Brush object, now its time for some Pen stuff.

While the Brush classes are used to fill shapes, the Pen class is used to frame shapes. However, Pens are not only used for simple frames. Here in this post I show some advanced uses for the Pen. [more]

Some interesting members are :

As you can see, the pen can be instantiated with a Color or with a defined Brush that means the pen can be one of the Brush TypesI previously wrote about.

In addition to their brushlike behavior, pens have behavior at starting and ending along their length that brushes don’t have. For example, each end can have a different style, as determined by the LineCap enumeration shown next.

Line Caps

1

You can set different LineCaps for pens in the StartCap and EndCap properties of the Pen, there are predefined caps and custom caps are allowed too.

Dashes

In addition to the ends having special styles the starts can have as well, further more a line can have a dash style, as defined by the DashStyle enumeration.

Dash Style of Pen

As you can notice in the members of the Pen, the DashCap property which also accepts a LineCap enumeration, so you can take more control over the line that appears.
Thats all for this part. Happy Coding.

PensForm.cs (2.86 kb)

3 thoughts on “Exploring GDI+ : Using the Pen”

  1. I didn’t copy from the book, I honestly didn’t know that its there, I just checked it up and its ALMOST 100% like it.
    I don’t do copying all my previous posts as this one are of my own work.

    Any way thanks for the heads up I should have checked before writing.

  2. Good Job there … plz add more about drawing circles with the pen ..etc and nice work that your code exactly like mcts book …:D thats mean u r umbalanced .

Leave a Reply

Your email address will not be published. Required fields are marked *