Reputation: 13
Here's is my code:
type TNav = class(TPanel)
private
procedure CMMouseEnter(var AMsg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var AMsg: TMessage); message CM_MOUSELEAVE;
public
end;
type TForm1 = class(TForm)
...
procedure FormCreate(Sender: TObject);
private
public
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with TNav.Create(Form1) do begin
Parent := Self;
Name := 'nav';
Top := 0;
Left := 0;
Height := 27;
Width := Form1.Width - 8;
Visible := true;
Caption := '';
end;
end;
procedure TNav.CMMouseEnter(var AMsg: TMessage);
begin
Self.Top := 0;
end;
procedure TNav.CMMouseLeave(var AMsg: TMessage);
begin
Self.Top := -23;
end;
Is there a way to add an onResize event for my TNav, or even to send the width/height values from the Form1?
Thank you in advance!
Upvotes: 1
Views: 1122
Reputation: 108963
Do you want to add a "OnResize" handler to every instance of the TNav
(internally), or do you just want the TNav
to display a OnResize
event so that you can set it in the application? In the first case, just do
type
TNav = class(TPanel)
private
procedure CMMouseEnter(var AMsg: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var AMsg: TMessage); message CM_MOUSELEAVE;
protected
procedure Resize; override;
public
end;
and
procedure TNav.Resize;
begin
inherited;
// Do something
end;
In the latter case, just add
published
property OnResize;
To access the properties of the parent form (if any), in the TNav
class do (for example)
GetParentForm(Self).Width
By the way, are you aware of the Anchors
property of TPanel
? Add a TPanel
to a form, and set Anchors := [akLeft,akTop,akRight]
in the Property Editor. Is this something you can use?
Upvotes: 2