带有类对象的 onResize 事件
这是我的代码:
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;
有没有办法为我的 TNav 添加 onResize 事件,甚至从 Form1 发送宽度/高度值?
先感谢您!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否想要向
TNav
的每个实例添加“OnResize”处理程序(内部),或者您只想让TNav
显示OnResize event 以便您可以在应用程序中设置它?在第一种情况下,只需执行
和
在后一种情况下,只需添加
要访问父表单的属性(如果有),请在
TNav
类中执行(例如)顺便说一下,您是知道
TPanel
的Anchors
属性吗?将TPanel
添加到表单,并在属性编辑器中设置Anchors := [akLeft,akTop,akRight]
。这是你可以使用的东西吗?Do you want to add a "OnResize" handler to every instance of the
TNav
(internally), or do you just want theTNav
to display aOnResize
event so that you can set it in the application? In the first case, just doand
In the latter case, just add
To access the properties of the parent form (if any), in the
TNav
class do (for example)By the way, are you aware of the
Anchors
property ofTPanel
? Add aTPanel
to a form, and setAnchors := [akLeft,akTop,akRight]
in the Property Editor. Is this something you can use?