Delphi模拟最小化恢复关闭按纽,Delphi模拟最小化恢复关闭按纽
【 tulaoshi.com - Delphi 】
我们做多文档应用程序开发时,如果在主From中指定mainMenu时,在主菜单上右角上会自动出现最小化,恢复,关闭按纽,但主菜单放入Toolbar等中时,该三个按纽不会自动出现,因此需要编程实现。由于只有子窗体最大化时,这三个按纽才能出现,因此,需要在idel事件中去判断当前的子窗体的状态,以便决定这三个按纽是否隐藏或可见.
具体代码如下:
unit ufrmMain;
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/delphi/)interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ActnList, AppEvnts, ImgList, StdCtrls, Buttons, StdActns, Menus,
ToolWin, ComCtrls;
type
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/delphi/)//最大最小化按纽类
TMDIButton = class(TBitbtn)
private
public
//由于由Tbitn继承而来,因此需要屏蔽其获得焦点的消息
procedure wndproc(var message: Tmessage); override;
end;
TWindowMinimize = class(TWindowAction)
public
//按纽功能,将当前最前的子window状态改为wsMinimize;
procedure ExecuteTarget(Target: TObject); override;
end;
TWindowRestore = class(TWindowAction)
public
//按纽功能,将当前最前的子window状态改为wsNormal;
procedure ExecuteTarget(Target: TObject); override;
end;
TFrmMain = class(TForm)
//保存windows的最小化,恢复,关闭的图标
MDIImageList: TImageList;
//当程序不忙时,判断最大,最小化按纽的是否应该隐藏还是可见
ApplicationEvents1: TApplicationEvents;
//
ActMdiForm: TActionList;
ToolBar1: TToolBar;
MainMenu1: TMainMenu;
N1: TMenuItem;
open1: TMenuItem;
help1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
procedure FormResize(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure open1Click(Sender: TObject);
private
//模拟mdiform窗体最小化,关闭及恢复按纽对象
BtnMin, BtnRestore, BtnClose: TMDIButton;
Windowclose: TWindowClose;
WindowMinimize: TWindowMinimize;
WindowRestore: TWindowRestore;
procedure SetMDIFormActionPos;
public
{ Public declarations }
end;
var
FrmMain: TFrmMain;
implementation
{$R *.dfm}
procedure TFrmMain.FormCreate(Sender: TObject);
begin
//建立关闭Button
BtnClose := TMDIButton.Create(self);
BtnClose.Visible := false;
BtnClose.Parent := self;
BtnClose.Width := 16;
Btnclose.Height := 15;
//建立关闭功能Action
WindowClose := TWindowClose.Create(nil);
//指定其图标
WindowClose.ActionList := ActMdiForm;
WindowClose.ImageIndex := 2; //关闭;
WindowClose.Caption := ;
//将action与button关联
BtnClose.Action := WindowClose;
BtnClose.BringToFront;
BtnClose.Visible := false;
//建立最小化Button
BtnMin := TMDIButton.Create(self);
BtnMin.Visible := false;
BtnMin.Parent := self;
BtnMin.width := 16;
BtnMin.height := 15;
//建立最小化功能action
WindowMinimize := TWindowMinimize.Create(nil);
//指定其图标
WindowMinimize.ActionList := ActMdiForm;
WindowMinimize.Caption := ;
WindowMinimize.ImageIndex := 0;
//将action与button关联
BtnMin.Action := WindowMinimize; //最小化
BtnMin.BringToFront;
BtnMin.Visible := false;
//建立恢复功能Button
BtnRestore := TMDIButton.Create(self);
来源:http://www.tulaoshi.com/n/20160129/1493410.html
看过《Delphi模拟最小化恢复关闭按纽》的人还看了以下文章 更多>>