德尔福XE2风格画 [英] Delphi XE2 styles painting

查看:199
本文介绍了德尔福XE2风格画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

绘制VCL样式的窗口元素时,我遇到错误绘制的角落时遇到问题。在具有圆角的样式上,我在控件的边界和风格的圆角之间的空白处获得了白色背景。





上面的图像是使用Aqua Light Slate运行的,但是任何风格圆角会显示同样的问题。我缺少什么?

  type 
TSample = class(TCustomControl)
保护
程序油漆;覆盖
结束

{TForm1}
procedure TForm1.FormCreate(Sender:TObject);
var
R:TRect;
S:TSample;
begin
R:= ClientRect;
InflateRect(R,-20,-20);
S:= TSample.Create(Application);
S.Parent:=自我;
S.BoundsRect:= R;
结束

{TSample}
procedure TSample.Paint;
var
详细信息:TThemedElementDetails;
begin
详细信息:= StyleServices.GetElementDetails(twCaptionActive);
StyleServices.DrawParentBackground(Self.Handle,Canvas.Handle,Details,False);
StyleServices.DrawElement(Canvas.Handle,Details,ClientRect);
结束


解决方案

好的,我花了几分钟在你的问题找到答案。绘制圆角的关键是调用 StyleServices.GetElementRegion 功能获取该区域,然后使用 SetWindowRgn 功能将该区域应用于控件。



检查此样本

  procedure TSample.Paint; 
var
详细信息:TThemedElementDetails;
区域:HRgn;
LRect:TRect;
begin
详细信息:= 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);
结束

这是结果



< img src =https://i.stack.imgur.com/FBW2j.pngalt =在此输入图像说明>


I am having trouble with incorrectly painted corners when drawing VCL-styled window elements. On styles that have rounded corners, I get a white background in the space between the control's bounding rect and the style's rounded window corner.

The above image was run using Aqua Light Slate, but any style with rounded corners will show this 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;

解决方案

Ok, I spend some minutes in you question and I found the answer. The key to draw the rounded corners, is call the StyleServices.GetElementRegion function to get the region and then use the SetWindowRgn function to apply the region 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

这篇关于德尔福XE2风格画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆