W
wwwwww
Unregistered / Unconfirmed
GUEST, unregistred user!
GROUPBOX的边颜色不能改,我就继承了一个,新增加了两个属性,
谁知:
1.设计时怎么改属性,它就是不变,不重画,WHY?
2.强行拖动它的边缘改变大小后,COLOR有了作用,WHY?
3.设计时调整得再好,但运行时又重置成默认的黑色了,WHY?
请看我的源码,尤其是???部分,谁能帮我改改?
...
type
TmyGroupBox = class(TGroupBox)
private
FFrameCanSet: boolean;//新增的属性,是否用用户自己的颜色
FFrameColor: Tcolor;//新的颜色
procedure SetFrameCanSet(const Value: boolean);
procedure SetFrameColor (const Value: Tcolor);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
published
property FrameCanSet:boolean read FFrameCanSet write SetFrameCanSet;
property FrameColor:Tcolor read FFrameColor write SetFrameColor;
end;
procedure Register;
implementation
constructor TmyGroupBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FrameCanSet:=false;
end;
procedure TmyGroupBox.Paint;
//COPY了STDCTRL.PAS里的一段程序,
并在////////////////////部分做了修改
var
H: Integer;
R: TRect;
Flags: Longint;
begin
with Canvas do
begin
Font := Self.Font;
H := TextHeight('0');
R := Rect(0, H div 2 - 1, Width, Height);
if Ctl3D then
begin
Inc(R.Left);
Inc(R.Top);
Brush.Color := clBtnHighlight;
FrameRect(R);
OffsetRect(R, -1, -1);
/////////////////////////////////////////??????????
if FrameCanSet
then Brush.color:=FFrameColor
else Brush.Color := clBtnShadow;
end
else
if FrameCanSet
then Brush.color:=FFrameColor
else Brush.Color := clWindowFrame;
////////////////////////////////////////////?????????
FrameRect(R);
if Text <> '' then
begin
if not UseRightToLeftAlignment then
R := Rect(8, 0, 0, H)
else
R := Rect(R.Right - Canvas.TextWidth(Text) - 8, 0, 0, H);
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);
DrawText(Handle, PChar(Text), Length(Text), R, Flags or DT_CALCRECT);
Brush.Color := Color;
DrawText(Handle, PChar(Text), Length(Text), R, Flags);
end;
end;
end;
procedure TmyGroupBox.SetFrameColor(const Value: Tcolor);
begin
if FFrameColor<>Value
then begin//强制重画,但死活不变!!!!!!!!!!!!!!why!!!!!!!!!!!!1
FFrameColor := Value;
Setbounds(left,top,width,height);
Invalidate;
paint;
refresh;
end;
end;
procedure TmyGroupBox.SetFrameCanSet(const Value: boolean);
begin
if FFrameCanSet<>Value
then begin FFrameCanSet := Value;
Setbounds(left,top,width,height);
paint;
Invalidate;
refresh;
end;
end;
谁知:
1.设计时怎么改属性,它就是不变,不重画,WHY?
2.强行拖动它的边缘改变大小后,COLOR有了作用,WHY?
3.设计时调整得再好,但运行时又重置成默认的黑色了,WHY?
请看我的源码,尤其是???部分,谁能帮我改改?
...
type
TmyGroupBox = class(TGroupBox)
private
FFrameCanSet: boolean;//新增的属性,是否用用户自己的颜色
FFrameColor: Tcolor;//新的颜色
procedure SetFrameCanSet(const Value: boolean);
procedure SetFrameColor (const Value: Tcolor);
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
published
property FrameCanSet:boolean read FFrameCanSet write SetFrameCanSet;
property FrameColor:Tcolor read FFrameColor write SetFrameColor;
end;
procedure Register;
implementation
constructor TmyGroupBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FrameCanSet:=false;
end;
procedure TmyGroupBox.Paint;
//COPY了STDCTRL.PAS里的一段程序,
并在////////////////////部分做了修改
var
H: Integer;
R: TRect;
Flags: Longint;
begin
with Canvas do
begin
Font := Self.Font;
H := TextHeight('0');
R := Rect(0, H div 2 - 1, Width, Height);
if Ctl3D then
begin
Inc(R.Left);
Inc(R.Top);
Brush.Color := clBtnHighlight;
FrameRect(R);
OffsetRect(R, -1, -1);
/////////////////////////////////////////??????????
if FrameCanSet
then Brush.color:=FFrameColor
else Brush.Color := clBtnShadow;
end
else
if FrameCanSet
then Brush.color:=FFrameColor
else Brush.Color := clWindowFrame;
////////////////////////////////////////////?????????
FrameRect(R);
if Text <> '' then
begin
if not UseRightToLeftAlignment then
R := Rect(8, 0, 0, H)
else
R := Rect(R.Right - Canvas.TextWidth(Text) - 8, 0, 0, H);
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);
DrawText(Handle, PChar(Text), Length(Text), R, Flags or DT_CALCRECT);
Brush.Color := Color;
DrawText(Handle, PChar(Text), Length(Text), R, Flags);
end;
end;
end;
procedure TmyGroupBox.SetFrameColor(const Value: Tcolor);
begin
if FFrameColor<>Value
then begin//强制重画,但死活不变!!!!!!!!!!!!!!why!!!!!!!!!!!!1
FFrameColor := Value;
Setbounds(left,top,width,height);
Invalidate;
paint;
refresh;
end;
end;
procedure TmyGroupBox.SetFrameCanSet(const Value: boolean);
begin
if FFrameCanSet<>Value
then begin FFrameCanSet := Value;
Setbounds(left,top,width,height);
paint;
Invalidate;
refresh;
end;
end;