We help IT Professionals succeed at work.

Avoiding radiused corner when drawing lines with pen

Medium Priority
642 Views
Last Modified: 2012-08-13
When using a wide pen width and drawing a square corner, I end up with a radius on the outside of the corner.  I know I've seen some canvas or pen property that addresses this but just can't find it.

Can anyone tell me how to create sharp outside corners?
Comment
Watch Question

Sr. Software Engineer
CERTIFIED EXPERT
Commented:
You'll have to change the handle of the pen yourself, see this example:
procedure TForm2.FormClick(Sender: TObject);
var LogBrush: TLogBrush;
begin
 Form2.Canvas.Pen.Width := 10;
 
 // 'normal' draw
 Form2.canvas.MoveTo(10, 10);
 Form2.canvas.LineTo(100, 10);
 Form2.canvas.lineto(100, 100);
 
 // now change the pen style
 LogBrush.lbStyle := BS_SOLID;
 LogBrush.lbColor :=  Form2.Canvas.Pen.Color;
 LogBrush.lbHatch := 0;
 
 Form2.Canvas.Pen.Handle := extCreatePen(PS_GEOMETRIC or PS_SOLID or PS_ENDCAP_SQUARE or PS_JOIN_MITER,
                                         Form2.Canvas.Pen.Width,
                                         LogBrush,
                                         0,
                                         nil);
 
 // draw with square ends
 Form2.canvas.MoveTo(10, 150);
 Form2.canvas.LineTo(100, 150);
 Form2.canvas.lineto(100, 250);
end;

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
The problem involved only a minor cosmetic annoyance - but it irritated me!   Nice solution, exceedingly well documented.  Thanks a lot.

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.