首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

怎么frame添加Onshow事件~以及怎么调用frame

2012-04-26 
如何frame添加Onshow事件~以及如何调用frame例如说现在我有个form1的窗体,有frame1和frame2两个框架结构,b

如何frame添加Onshow事件~以及如何调用frame
例如说现在我有个form1的窗体,有frame1和frame2两个框架结构,button1和button2两个按键。
  现在想实现如下功能:当我点击Button1时,在form1中显示frame1;点击button2时,在form1中显示frame2,并且给两个frame添加onshow控件。
  我一开始以为就像在form1中引用其他form一样,在form1中添加类似于 uses frame1,frame2这样的调用语句~但肯定是不行!
  所以我想问的问题有两个:
  1.如何在form1中调用不同frame,实现上述功能;
  2.如何给frame添加onshow事件,当不同frame显示时,在frame中显示出我想要的信息。
  这个问题这两天都一直不能解决,谢谢各位啊!

[解决办法]
type
TFrame2 = class(TFrame)
Button1: TButton;
private
{ Private declarations }
public
constructor create(AOwner: TComponent);override;
procedure test();
end;

implementation

{$R *.dfm}
constructor TFrame2.create(AOwner: TComponent);
begin
inherited;
ShowMessage('test');//这个在创建FRAME时会执行相当于onCREATE事件。
end;
procedure TFrame2.test();
begin
//也可以在创建实例后调用TEST方法
end;
end.

[解决办法]
1. button1: frame1.show;frame2.hide
button2: frame1.hide;frame2.show

2.
type
Tframe1 = class(TFrame)
...
private
{ Private declarations }
procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED;

...

procedure Tframe1.CMShowingChanged(var Message: TMessage);
begin
if Showing then
begin
try
ShowMessage('frame1 show!!!!')
except
Application.HandleException(Self);
end;
end;

inherited;
end;

热点排行