请教关于控件的重画问题 ( 积分: 50 )

  • 主题发起人 主题发起人 qylin1
  • 开始时间 开始时间
Q

qylin1

Unregistered / Unconfirmed
GUEST, unregistred user!
我继承 TCustomControl 生成一个 GroupBox 控件,在 Paint 过程里对 Canvas 进行了重画的操作

R := Rect(0, 0, Width, Height);
FillRect(R);

在运行的时候, 这个 GroupBox 里有一个 ListView 控件(ViewStyle=vsReport), 当GroupBox 进行重画的时候, ListView 的标题行就会清除,无法显示。

请问,这是什么问题造成的,应该如何解决?无限感谢!
 
请贴多点代码

Paint里面有没有这行

inherited
 
procedure TQGroupBox.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Begin
Style := Style and Not WS_CLIPCHILDREN;
Style := Style and Not WS_CLIPSIBLINGS;

WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
End ;
end;

procedure TQGroupBox.Paint;
var
H: Integer;
R, R1: TRect;
Flags: Longint;
CaptionRect,
OuterRect: TRect;
Size: TSize;
Box: TThemedButton;
Details: TThemedElementDetails;
begin
with Canvas do
begin
Font := Self.Font;

Brush.Style := bsClear ;

R := Rect(0, 0, Width, Height);
FillRect(R);

if Text <> '' then
H := TextHeight('0')
Else
H := 2 ;
R := Rect(0, H div 2 - 1, Width, Height);
If FShowBox Then
Begin
if Ctl3D then
begin
Inc(R.Left);
Inc(R.Top);
Pen.Color := clBtnHighlight ;
RoundRect(R.Left, R.Top, R.Right, R.Bottom, FAngle, FAngle);
OffsetRect(R, -1, -1);
Pen.Color := clWindowText ;
end
else
begin
Pen.Color := BoxColor ;
Font.Color := BoxColor ;
end ;
RoundRect(R.Left, R.Top, R.Right, R.Bottom, FAngle, FAngle);
End ;

Brush.Style := bsSolid ;
if Text <> '' then
begin
if not UseRightToLeftAlignment then
R := Rect(10, 0, 0, H)
else
R := Rect(R.Right - Canvas.TextWidth(Text) - FAngle + 3, 0, 0, H);
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);
DrawText(Handle, PChar(Text), Length(Text), R, Flags or DT_CALCRECT);
Brush.Color := Color;

If Not Enabled Then
Begin
Font.Color := clBtnHighlight;
R1 := Rect(R.Left + 1, R.Top + 1, R.Right, R.Bottom) ;
DrawText(Handle, PChar(Text), Length(Text), R1, Flags);
Font.Color := clBtnShadow;
Brush.Style := bsClear ;
End ;

DrawText(Handle, PChar(Text), Length(Text), R, Flags);
end;
end;
inherited;
end;

procedure TQGroupBox.CMEnabledChanged(var Message: TMessage);
Var
i: Integer ;
begin
inherited;
Invalidate;
If ControlCount < 1 Then Exit ;
For i := 0 To ControlCount - 1 Do
Begin
Controls.Enabled := Enabled ;
End ;
end;
 
有人给点提示吗,谢谢了
 
Style := Style and Not WS_CLIPSIBLINGS;

WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
这两个不要好像就行了啊
 
后退
顶部