Delphi draws a closed rectangle with two rounded corners and rectangular corners
How can I draw a rectangle with 2 round corners and the opposite corners are rectangular. The shape must be closed so that it can be filled with the brush color. The Polyline method does not draw curved lines. Can I add arc points to polyline points? I tried using RoundRect using the Canvas method and then overlaying a rectangle on the bottom rounded corners, but I couldn't figure out how to erase the top line of the rectangle when only drawing the shape border without filling it. Note: if you deem relevant, I can add the code I used.
Sample of the required shape:
An example of what I got with Delphi:
source to share
You don't need to fill the shape at the same time you draw it. You can first use a series of calls TCanvas.LineTo()
and TCanvas.ArcTo()
/ TCanvas.AngleArc()
to create the shape, and then call TCanvas.FloodFill()
afterwards to fill it.
Otherwise, you can overlap TCanvas.Rectangle()
on top TCanvas.RoundRect()
with the same fill color and then use TCanvas.MoveTo()
/ TCanvas.LineTo()
to draw along the dividing line with the same fill color.
Another option is to forget to use drawing methods TCanvas
and just use the Win32 API calls. Use CreateRoundRectRgn()
, CreateRectRgn()
and CombineRn()
to create HRGN
which has the desired shape, then use FillRgn()
and FrameRgn()
to draw yours TCanvas
using HRGN
.
source to share