我刚编写的控件,你自己参考 { Author: Guo XianHai YanShan University E-mail: [email protected] if you have amend,please send a copy to me If you have any comments, suggestions or anything else you want to tell me, don't hesitate to drop me a line. 作者: 郭贤海 中国 燕山大学 有做了任何修改,请发一份Copy给我 如果你有任何的建议或者其他想告诉我的,不要犹豫,请马上写信给我 2001-08-30}unit PanRB;interfaceuses Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, StdCtrls;type TPRB = class(TCustomPanel) private { Private declarations } FBevelL:TBevel; FRB:array[0..4] of TRadioButton; procedure WMSize(var Message: TWMSize); message WM_SIZE; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; procedure Clear; function GetResult:string; function IsHollow:boolean; published { Published declarations } property Caption; property Font; property ParentFont; end;type TPanRB = class(TPRB) private { Private declarations } FRBWidth:Integer; procedure SetRBWidth(Value: Integer); procedure WMSize(var Message: TWMSize); message WM_SIZE; protected { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; published { Published declarations } property RBWidth: Integer read FRBWidth write SetRBWidth; end;type TPanRBChk = class(TPRB) private { Private declarations } FBevelLLeft:Integer; FCheckBoxWidth:Integer; FBevelR:TBevel; FCheckBox:TCheckBox; FRBEnabled: boolean; FOnRBClick: TNotifyEvent; procedure SetBevelLLeft(Value: Integer); procedure WMSize(var Message: TWMSize); message WM_SIZE; procedure SetFCheckBoxWidth(const Value: Integer); procedure SetFRBEnabled(const Value: boolean); procedure FChkClick(Sender: TObject); procedure FRBClick(Sender: TObject); protected { Protected declarations } procedure DoRBClick(Sender: TObject);dynamic; public { Public declarations } constructor Create(AOwner: TComponent); override; published { Published declarations } property BevelLLeft: Integer read FBevelLLeft write SetBevelLLeft; property CheckBoxWidth: Integer read FCheckBoxWidth write SetFCheckBoxWidth; property RBEnabled: boolean read FRBEnabled write SetFRBEnabled; property OnRBClick: TNotifyEvent read FOnRBClick write FOnRBClick; end;procedure Register;implementationprocedure Register; begin RegisterComponents('Guo', [TPanRB,TPanRBChk]); end;{ TPRB }procedure TPRB.Clear; var i:Integer; begin for i:=0 to 4 do FRB[i].Checked:=False; end;constructor TPRB.Create(AOwner: TComponent); var i,t:Integer; begin inherited Create(AOwner); Alignment:=taLeftJustify; Font.Name:='宋体'; Font.Size:=14; Height:=31; BevelInner:=bvRaised; BevelOuter:=bvLowered; FBevelL:=TBevel.Create(Self); FBevelL.Parent:=Self; FBevelL.Shape:=bsLeftLine; FBevelL.Top:=1; FBevelL.Height:=Height-2; FBevelL.Width:=4; FBevelL.Visible:=True; for i:=0 to 4 do begin FRB[i]:=TRadioButton.Create(Self); FRB[i].Parent:=Self; FRB[i].Caption:=Chr(i+65); FRB[i].Visible:=True; end; t:=Height-FRB[0].Height; t:=t div 2; for i:=0 to 4 do FRB[i].Top:=t; end;procedure TPRB.WMSize(var Message: TWMSize); var i,t:Integer; begin inherited; t:=Height-FRB[0].Height; t:=t div 2; for i:=0 to 4 do FRB[i].Top:=t; FBevelL.Height:=Height-2; RePaint; end;function TPRB.GetResult: string; var i:Integer; begin Result:=''; for i:=0 to 4 do if FRB[i].Checked then begin Result:=FRB[i].Caption; Exit; end; end;function TPRB.IsHollow: boolean; var i:Integer; begin Result:=True; for i:=0 to 4 do if FRB[i].Checked then begin Result:=False; Exit; end; end;{ TPanRB }constructor TPanRB.Create(AOwner: TComponent); var i,w:Integer; begin inherited Create(AOwner); Width:=369; FRBWidth:=280; FBevelL.Left:=Width-FRBWidth; w:=(FRBWidth-14) div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelL.Left; FRB[i].Width:=w; end; end;procedure TPanRB.SetRBWidth(Value: Integer); var i,w:Integer; begin if FRBWidth<>Value then begin FRBWidth:=Value; FBevelL.Left:=Width-FRBWidth; w:=(FRBWidth-14) div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelL.Left; FRB[i].Width:=w; end; end; end;procedure TPanRB.WMSize(var Message: TWMSize); var i,w:Integer; begin inherited; FBevelL.Left:=Width-FRBWidth; w:=(FRBWidth-14) div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelL.Left; FRB[i].Width:=w; end; RePaint; end;{ TPanRBChk }constructor TPanRBChk.Create(AOwner: TComponent); var i,w,t:Integer; begin inherited Create(AOwner); Width:=351; FBevelR:=TBevel.Create(Self); FBevelR.Parent:=Self; FBevelR.Shape:=bsLeftLine; FBevelR.Top:=1; FBevelR.Height:=Height-2; FBevelR.Width:=4; FBevelR.Visible:=True; FBevelLLeft:=29; FBevelL.Left:=FBevelLLeft; FCheckBoxWidth:=35; FBevelR.Left:=Width-FCheckBoxWidth; w:=Width-FBevelLLeft-FCheckBoxWidth-14; w:=w div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelLLeft; FRB[i].Width:=w; FRB[i].OnClick:=FRBClick; end; FCheckBox:=TCheckBox.Create(Self); FCheckBox.Parent:=Self; FCheckBox.Width:=FCheckBoxWidth-8; FCheckBox.Left:=FBevelR.Left+4; FCheckBox.Top:=FRB[0].Top; FCheckBox.Visible:=True; FCheckBox.OnClick:=FChkClick; FRBEnabled:=True; end;procedure TPanRBChk.DoRBClick(Sender: TObject); begin if Assigned(FOnRBClick) then FOnRBClick(Self); end;procedure TPanRBChk.FChkClick(Sender: TObject); var i:Integer; begin for i:=0 to 4 do FRB[i].Enabled:=FCheckBox.Checked; if not FCheckBox.Checked then for i:=0 to 4 do FRB[i].Checked:=False; end;procedure TPanRBChk.FRBClick(Sender: TObject); begin FCheckBox.Checked:=True; DoRBClick(Sender); end;procedure TPanRBChk.SetBevelLLeft(Value: Integer); var i,w:Integer; begin if FBevelLLeft<>Value then begin FBevelLLeft:=Value; FBevelL.Left:=FBevelLLeft; w:=Width-FBevelLLeft-FCheckBoxWidth-14; w:=w div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelLLeft; FRB[i].Width:=w; end; end; end;procedure TPanRBChk.SetFCheckBoxWidth(const Value: Integer); var i,w:Integer; begin if FCheckBoxWidth<>Value then begin FCheckBoxWidth := Value; FCheckBox.Left:=FCheckBoxWidth+4; FCheckBox.Width:=FCheckBoxWidth-8; FBevelR.Left:=Width-FCheckBoxWidth; w:=Width-FBevelLLeft-FCheckBoxWidth-14; w:=w div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelLLeft; FRB[i].Width:=w; end; end; end;procedure TPanRBChk.SetFRBEnabled(const Value: boolean); var i:Integer; begin if FRBEnabled<>Value then begin FRBEnabled := Value; for i:=0 to 4 do begin FRB[i].Enabled:=FRBEnabled; FRB[i].Checked:=False; end; end; end;procedure TPanRBChk.WMSize(var Message: TWMSize); var i,w,t:Integer; begin inherited; w:=Width-FBevelLLeft-FCheckBoxWidth-14; w:=w div 5; for i:=0 to 4 do begin FRB[i].Left:=i*w+8+FBevelLLeft; FRB[i].Width:=w; end; FBevelR.Height:=Height-2; FBevelR.Left:=Width-FCheckBoxWidth; FCheckBox.Left:=FBevelR.Left+4; FCheckBox.Top:=FRB[0].Top; RePaint; end;end.
{ Author:
Guo XianHai
YanShan University
E-mail: [email protected] if you have amend,please send a copy to me
If you have any comments, suggestions or anything else you
want to tell me, don't hesitate to drop me a line.
作者:
郭贤海
中国 燕山大学 有做了任何修改,请发一份Copy给我
如果你有任何的建议或者其他想告诉我的,不要犹豫,请马上写信给我
2001-08-30}unit PanRB;interfaceuses
Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, StdCtrls;type
TPRB = class(TCustomPanel)
private
{ Private declarations }
FBevelL:TBevel;
FRB:array[0..4] of TRadioButton;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
procedure Clear;
function GetResult:string;
function IsHollow:boolean;
published
{ Published declarations }
property Caption;
property Font;
property ParentFont;
end;type
TPanRB = class(TPRB)
private
{ Private declarations }
FRBWidth:Integer;
procedure SetRBWidth(Value: Integer);
procedure WMSize(var Message: TWMSize); message WM_SIZE;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property RBWidth: Integer read FRBWidth write SetRBWidth;
end;type
TPanRBChk = class(TPRB)
private
{ Private declarations }
FBevelLLeft:Integer;
FCheckBoxWidth:Integer;
FBevelR:TBevel;
FCheckBox:TCheckBox;
FRBEnabled: boolean;
FOnRBClick: TNotifyEvent;
procedure SetBevelLLeft(Value: Integer);
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure SetFCheckBoxWidth(const Value: Integer);
procedure SetFRBEnabled(const Value: boolean);
procedure FChkClick(Sender: TObject);
procedure FRBClick(Sender: TObject);
protected
{ Protected declarations }
procedure DoRBClick(Sender: TObject);dynamic;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
published
{ Published declarations }
property BevelLLeft: Integer read FBevelLLeft write SetBevelLLeft;
property CheckBoxWidth: Integer read FCheckBoxWidth write SetFCheckBoxWidth;
property RBEnabled: boolean read FRBEnabled write SetFRBEnabled;
property OnRBClick: TNotifyEvent read FOnRBClick write FOnRBClick;
end;procedure Register;implementationprocedure Register;
begin
RegisterComponents('Guo', [TPanRB,TPanRBChk]);
end;{ TPRB }procedure TPRB.Clear;
var i:Integer;
begin
for i:=0 to 4 do FRB[i].Checked:=False;
end;constructor TPRB.Create(AOwner: TComponent);
var
i,t:Integer;
begin
inherited Create(AOwner);
Alignment:=taLeftJustify;
Font.Name:='宋体';
Font.Size:=14;
Height:=31;
BevelInner:=bvRaised;
BevelOuter:=bvLowered; FBevelL:=TBevel.Create(Self);
FBevelL.Parent:=Self;
FBevelL.Shape:=bsLeftLine;
FBevelL.Top:=1;
FBevelL.Height:=Height-2;
FBevelL.Width:=4;
FBevelL.Visible:=True; for i:=0 to 4 do
begin
FRB[i]:=TRadioButton.Create(Self);
FRB[i].Parent:=Self;
FRB[i].Caption:=Chr(i+65);
FRB[i].Visible:=True;
end; t:=Height-FRB[0].Height;
t:=t div 2;
for i:=0 to 4 do FRB[i].Top:=t;
end;procedure TPRB.WMSize(var Message: TWMSize);
var i,t:Integer;
begin
inherited;
t:=Height-FRB[0].Height;
t:=t div 2;
for i:=0 to 4 do FRB[i].Top:=t; FBevelL.Height:=Height-2;
RePaint;
end;function TPRB.GetResult: string;
var i:Integer;
begin
Result:='';
for i:=0 to 4 do
if FRB[i].Checked then
begin
Result:=FRB[i].Caption;
Exit;
end;
end;function TPRB.IsHollow: boolean;
var i:Integer;
begin
Result:=True;
for i:=0 to 4 do
if FRB[i].Checked then
begin
Result:=False;
Exit;
end;
end;{ TPanRB }constructor TPanRB.Create(AOwner: TComponent);
var
i,w:Integer;
begin
inherited Create(AOwner);
Width:=369; FRBWidth:=280;
FBevelL.Left:=Width-FRBWidth; w:=(FRBWidth-14) div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelL.Left;
FRB[i].Width:=w;
end;
end;procedure TPanRB.SetRBWidth(Value: Integer);
var i,w:Integer;
begin
if FRBWidth<>Value then
begin
FRBWidth:=Value;
FBevelL.Left:=Width-FRBWidth;
w:=(FRBWidth-14) div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelL.Left;
FRB[i].Width:=w;
end;
end;
end;procedure TPanRB.WMSize(var Message: TWMSize);
var i,w:Integer;
begin
inherited;
FBevelL.Left:=Width-FRBWidth;
w:=(FRBWidth-14) div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelL.Left;
FRB[i].Width:=w;
end; RePaint;
end;{ TPanRBChk }constructor TPanRBChk.Create(AOwner: TComponent);
var
i,w,t:Integer;
begin
inherited Create(AOwner);
Width:=351; FBevelR:=TBevel.Create(Self);
FBevelR.Parent:=Self;
FBevelR.Shape:=bsLeftLine;
FBevelR.Top:=1;
FBevelR.Height:=Height-2;
FBevelR.Width:=4;
FBevelR.Visible:=True; FBevelLLeft:=29;
FBevelL.Left:=FBevelLLeft;
FCheckBoxWidth:=35;
FBevelR.Left:=Width-FCheckBoxWidth; w:=Width-FBevelLLeft-FCheckBoxWidth-14;
w:=w div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelLLeft;
FRB[i].Width:=w;
FRB[i].OnClick:=FRBClick;
end; FCheckBox:=TCheckBox.Create(Self);
FCheckBox.Parent:=Self;
FCheckBox.Width:=FCheckBoxWidth-8;
FCheckBox.Left:=FBevelR.Left+4;
FCheckBox.Top:=FRB[0].Top;
FCheckBox.Visible:=True;
FCheckBox.OnClick:=FChkClick; FRBEnabled:=True;
end;procedure TPanRBChk.DoRBClick(Sender: TObject);
begin
if Assigned(FOnRBClick) then FOnRBClick(Self);
end;procedure TPanRBChk.FChkClick(Sender: TObject);
var i:Integer;
begin
for i:=0 to 4 do FRB[i].Enabled:=FCheckBox.Checked;
if not FCheckBox.Checked then
for i:=0 to 4 do FRB[i].Checked:=False;
end;procedure TPanRBChk.FRBClick(Sender: TObject);
begin
FCheckBox.Checked:=True;
DoRBClick(Sender);
end;procedure TPanRBChk.SetBevelLLeft(Value: Integer);
var i,w:Integer;
begin
if FBevelLLeft<>Value then
begin
FBevelLLeft:=Value;
FBevelL.Left:=FBevelLLeft;
w:=Width-FBevelLLeft-FCheckBoxWidth-14;
w:=w div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelLLeft;
FRB[i].Width:=w;
end;
end;
end;procedure TPanRBChk.SetFCheckBoxWidth(const Value: Integer);
var i,w:Integer;
begin
if FCheckBoxWidth<>Value then
begin
FCheckBoxWidth := Value;
FCheckBox.Left:=FCheckBoxWidth+4;
FCheckBox.Width:=FCheckBoxWidth-8;
FBevelR.Left:=Width-FCheckBoxWidth;
w:=Width-FBevelLLeft-FCheckBoxWidth-14;
w:=w div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelLLeft;
FRB[i].Width:=w;
end;
end;
end;procedure TPanRBChk.SetFRBEnabled(const Value: boolean);
var i:Integer;
begin
if FRBEnabled<>Value then
begin
FRBEnabled := Value;
for i:=0 to 4 do
begin
FRB[i].Enabled:=FRBEnabled;
FRB[i].Checked:=False;
end;
end;
end;procedure TPanRBChk.WMSize(var Message: TWMSize);
var i,w,t:Integer;
begin
inherited;
w:=Width-FBevelLLeft-FCheckBoxWidth-14;
w:=w div 5;
for i:=0 to 4 do
begin
FRB[i].Left:=i*w+8+FBevelLLeft;
FRB[i].Width:=w;
end; FBevelR.Height:=Height-2;
FBevelR.Left:=Width-FCheckBoxWidth;
FCheckBox.Left:=FBevelR.Left+4;
FCheckBox.Top:=FRB[0].Top; RePaint;
end;end.