开发圆角Panel的问题,老闪!
我写了个圆角的panel组件,重绘的时候会一直闪烁,设计期和运行期都是如此,请大家看看!
这是Paint事件
procedure TRoundPanel.Paint;
var
rect:TRect;
i:integer;
tmpPS:PAINTSTRUCT;
myHDC:HDC;
begin
if FRoundPanel then
begin
rect:=self.ClientRect;
myHDC:=BeginPaint(Handle,tmpPS);
for i:=5 downto 1 do
begin
canvas.Pen.Color:= BaseColor+FStepColor;
canvas.RoundRect(rect.Left+i,rect.Top+i,rect.Right-i,rect.Bottom-i,FRoundWidth,FRoundHeight);
end;
RoundClientArea;
EndPaint(Handle,tmpPS);
end;
inherited Paint;
end;
//是下面这个事件导致闪烁
procedure TRoundPanel.RoundClientArea;
var
rect:Trect;
rgn:Hrgn;
begin
rect:=self.ClientRect;
Rgn:=CreateRoundRectRgn(rect.Left,rect.Top,rect.Right,rect.Bottom,FRoundWidth,FRoundHeight);
setWindowRgn(self.Handle,rgn,true);(是这个语句导致的)
end;