Brush and Pen Control

Brush and Pen Control - Beautify Your UIs with Perfect Pen...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon Printed from Beautify Your UIs with Perfect Pen and Brush Control Spice up your interfaces by taking full advantage of the Pen and Brush classes capabilities in the .NET Framework. Learn to create dashed and striped lines, control line joins, and use brushes to create interesting patterns and gradients. by Rod Stephens f you've done any Windows graphics programming at all, you know about Pens and Brushes. Pens determine the characteristics of lines, such as color and thickness. Brushes determine the characteristics of filled areas, notably the fill color. Many programmers use the Pens class to get stock, one-pixel wide pens of various colors as in the code e.Graphics.DrawLine(Pens.Red, 10, 10, 100, 100). They also use the Brushes class to get stock solid colored brushes as in: e.Graphics.FillEllipse(Brushes.Beige, _ New Rectangle(10, 10, 50, 100)) But Pens and Brushes can do more—much more. Line Joins When you use the DrawLines or DrawPolygon methods to draw a series of connected lines, you can choose to connect the lines in one of the four ways shown in Figure 1 . The thick orange lines show the join styles and thin black lines drawn on top show where the lines are actually drawn. The Bevel style cuts the corners off at each turn so the bevel touches a point where two lines meet. The bevel's angle is evenly spaced between the angles of the incoming and outgoing lines. If you think of the line as a laser beam, the bevel is like a mirror making it bounce from one line to the next. The Miter style extends the sides of the lines at a corner until they meet. For very sharp turns, that can make the corner stick pretty far out. The MiterClipped style is the same as Miter unless a corner sticks out too far in which case it switches to Bevel. Finally the Round style makes the corners rounded so the edge of the line is the same distance from the lines at all times. To use a particular join style, you first create a Pen object and then set its LineJoin property as shown in the following code: ' Use an orange Pen, 10 pixels wide. Using the_pen As New Pen(Color.Orange, 10) the_pen.LineJoin = LineJoin.Round e.Graphics.DrawLines(the_pen, pts) End Using Most of the Pen techniques described in this article follow a similar pattern: you create a Pen and then modify Figure 1 . Line Join Styles: Here's the output of the sample program "LineJoins," which demonstrates line join styles. Author's Note: The new Using statement automatically calls a Pen's or Brush's Dispose method, so I often employ it to simplify the code when dealing with Pens and Brushes. Page 1 of 8 Beautify Your UIs with Perfect Pen and Brush Control 11/22/2006
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
the Pen's properties. Line Caps
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 8

Brush and Pen Control - Beautify Your UIs with Perfect Pen...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online