[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

Avoiding radiused corner when drawing lines with pen

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?
0
DMTrump
Asked:
DMTrump
1 Solution
 
MerijnBSr. Software EngineerCommented:
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

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

0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now