سلام
من می خواهم یک کامپوننت بنویسم که به جای Button از اون استفاده کنم تا حالا هم کامپوننتی ننوشتم . برای این کار یک کامپوننت با وراثت از پنل ایجاد کردم و یک label و shape در اون قرار دادم . فقط shape رو به صورت client تعریف کردم . حالا می خواهم وقتی پنل رو تغییر سایز میدم این label هم تغییر سایز پیدا کنه اما نمی دونم چه جوری این کار باید انجام بدم لطفا راهنمای کنین . باید چه طوری میزان Heightو width برچسب و با مقدار Heightو width پنل برابر کنم . البته باید برای برچسبم این میزان کوچکتر باشد .
کد اولیم و اینجا گذاشتم . از دوستانی که لطف میکنند و جواب میدن ممنون .
unit HRCButton;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,StdCtrls,Graphics;
type
THRCButton = class(TPanel)
private
SHButton: TShape;
LBButton:tlabel;{ Private declarations }
FOnClick_LBButton: TNotifyEvent ;
procedure SetCaption_LBButton(newValue: TCaption);
function GetCaption_LBButton: TCaption;
procedure Click_LBButtonTransfer(Sender: TObject); { TNotifyEvent }
protected
procedure CreateWindowHandle(const Params: TCreateParams); override; { Protected declarations }
public
constructor Create(AOwner: TComponent); override;
{ Public declarations }
published
// property Width: Integer read GetWidth write SetWidth;
property Caption_LBButton: TCaption read GetCaption_LBButton write SetCaption_LBButton;
property OnClick_LBButton: TNotifyEvent read FOnClick_LBButton write FOnClick_LBButton;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('HRC', [THRCButton]);
end;
constructor THRCButton.Create(AOwner: TComponent);
{ Creates an object of type THRCButton, and initializes properties. }
begin
inherited Create(AOwner);
Left := 1;
Top := 1;
Width := 80;
Height := 28;
TabOrder := 0;
caption:='';
LbButton := Tlabel.Create(Self);
LBButton.Parent := Self;
SHButton := Tshape.Create(Self);
SHButton.Parent := Self;
end; { Create }
procedure THRCButton.CreateWindowHandle(const Params: TCreateParams);
{ Calls inherited CreateWindowHandle and initializes subcomponents. }
begin
inherited CreateWindowHandle(Params);
with LBButton do
begin
Left := 1;
Top := 1;
Width := 77;
Height := 25;
Cursor := crHandPoint;
Hint := 'Ctrl+P';
AutoSize := False;
BiDiMode := bdRightToLeft;
Caption := ' '#1575#1606#1589#1585#1575#1601;
Color := 6172194;
// Font.Charset := ARABIC_CHARSET;
Font.Color := clWhite;
Font.Height := -13;
Font.Name := 'Traffic';
Font.Style := [fsBold];
ParentBiDiMode := False;
ParentColor := False;
ParentFont := False;
ParentShowHint := False;
ShowHint := True;
Transparent := False;
end; { LB_Label }
with SHButton do
begin
Left := 1;
Top:= 1;
Width := 78;
Height := 26;
Cursor := crHandPoint;
Align := alClient;
Brush.Color := clBlack ;
Pen.Color:= clWhite;
Pen.Mode := pmMerge;
// ExplicitWidth := 79;
// ExplicitHeight := 25 ;
end; { SH_Shape }
end; { CreateWindowHandle }
function THRCButton.GetCaption_LBButton: TCaption;
{ Returns the Caption property from the LBButton subcomponent. }
begin
result := LBButton.Caption;
end; { GetCaption_LB_Button }
procedure THRCButton.SetCaption_LBButton(newValue: tCaption);
{ Sets the LBButton subcomponent's Caption property to newValue. }
begin
LBButton.Caption := newValue;
end; { SetCaption_LBButton }
procedure THRCButton.Click_LBButtonTransfer(Sender: TObject);
{ Transfers the LBButton OnClick event to the outside world. }
begin
if assigned(FOnClick_LBButton) then
FOnClick_LBButton(Self); { Substitute Self for subcomponent's Sender. }
end; { Click_LBButtonTransfer }
end.