Avoiding radiused corner when drawing lines with pen

Posted on 2009-02-18
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?
Question by:DMTrump
    LVL 19

    Accepted Solution

    You'll have to change the handle of the pen yourself, see this example:
    procedure TForm2.FormClick(Sender: TObject);
    var LogBrush: TLogBrush;
     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,
     // draw with square ends
     Form2.canvas.MoveTo(10, 150);
     Form2.canvas.LineTo(100, 150);
     Form2.canvas.lineto(100, 250);

    Open in new window


    Author Closing Comment

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


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    If you haven’t already, I encourage you to read the first article ( in my series to gain a basic foundation of R and R Studio.  You will also find the …
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now