Delphi XE2 Style Styles

I'm having problems with incorrectly painted corners when drawing window elements in VCL style. In styles that have rounded corners, I get a white background in the space between the bounding box of the control and the rounding angle of the style window.

enter image description here

The above image was made using the Aqua Light Slate, but any style with rounded corners will show the same problem. What am I missing?

type TSample = class(TCustomControl) protected procedure Paint; override; end; { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var R: TRect; S: TSample; begin R := ClientRect; InflateRect(R, -20, -20); S := TSample.Create(Application); S.Parent := Self; S.BoundsRect := R; end; { TSample } procedure TSample.Paint; var Details: TThemedElementDetails; begin Details := StyleServices.GetElementDetails(twCaptionActive); StyleServices.DrawParentBackground(Self.Handle, Canvas.Handle, Details, False); StyleServices.DrawElement(Canvas.Handle, Details, ClientRect); end; 
+3
source share
1 answer

Ok, I spend a few minutes in your question and I found the answer. The key to draw rounded corners is to call the StyleServices.GetElementRegion function to get the area, and then use SetWindowRgn to apply the area to the control.

check this sample

 procedure TSample.Paint; var Details : TThemedElementDetails; Region : HRgn; LRect : TRect; begin Details := StyleServices.GetElementDetails(twCaptionActive); LRect := Rect(0, 0, Width, Height); StyleServices.GetElementRegion(Details, LRect, Region); SetWindowRgn(Handle, Region, True); StyleServices.DrawParentBackground(Self.Handle, Canvas.Handle, Details, False); StyleServices.DrawElement(Canvas.Handle, Details, ClientRect); end; 

And this is the result

enter image description here

+4
source

Source: https://habr.com/ru/post/1482936/


All Articles