窗体架构方案(Tab页的功能)(100)

  • 主题发起人 主题发起人 paulwang200810
  • 开始时间 开始时间
P

paulwang200810

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么实现窗体像遨游(Maxthon)浏览器那样的Tab页切换。打开程序时默认是主窗体然后打开一个子窗体就增加一个tab页双击关闭tab页。 谢谢!
 
要是动态创建 不简单。。你可以是 先 设置好 有 20页 Tab ..然后刚运行的时候就把 19页 隐藏了。。然后 新建。就显示第一个。。双击。就隐藏一个。。
 
用 TFrame, 动态创建我的代码给你参考,这是我的软件的一个unit,详细看下面http://www.delphibbs.com/delphibbs/dispq.asp?lid=3972891unit baseFrame;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, RzTabs, main, Contnrs, mmsystem;type TfrBase = class; TwsTabSheet = class(TRzTabSheet) private { Private declarations } protected public Frame: TfrBase; { Public declarations } end; TfrBase = class(TFrame) pn: TPanel; private { Private declarations } wsTabSheet: TwsTabSheet; buttons: TcomponentList; procedure wmActive(var Msg: TMessage); message WM_ACTIVATE; procedure MMmciNotify(var Msg: TMessage); message MM_MCINOTIFY; public { Public declarations } vfIndex : integer; wsIndex : integer; voiceFiles : Tstrings; words : Tstrings; constructor CreateInPageControl(ACaption: string); destructor destroy; override; procedure settingColors; virtual; procedure init; virtual; procedure Next; virtual; procedure iniButtons; procedure loadData; virtual; procedure setBtVisible(value: boolean); end;implementation{$R *.dfm}{ TfrBase }uses myfunctions, myControls, srToolButton, dmMain, msgView;constructor TfrBase.CreateInPageControl(ACaption: string);begin if fmMain.ExistTabsheet(Acaption) then abort; wsTabSheet:=TwsTabsheet.Create(fmMain); wsTabSheet.PageControl:=fmMain.pageCtrl; wsTabSheet.Caption:=ACaption; inherited Create(wsTabSheet); wsTabSheet.Frame:=self; caption:=ACaption; parent:=wsTabSheet; init; words:=TstringList.Create; voiceFiles:=TstringList.Create; settingColors; wsTabSheet.Show; iniButtons; postmessage(handle, wm_Activate, 0, 0);end;destructor TfrBase.destroy;begin words.Free; voiceFiles.Free; buttons.Free; inherited;end;procedure TfrBase.iniButtons;var i: integer;begin if buttons = nil then buttons:=TcomponentList.Create; buttons.Clear; for i:=0 to pn.ControlCount-1 do buttons.Add(pn.Controls); buttons.Sort(@SortByTag); for i:=0 to buttons.Count-1 do begin TControl(buttons.Items).Left:=800; TControl(buttons.Items).Parent:=fmMain.Toolbar; TControl(buttons.Items).Align:=alLeft; end;end;procedure TfrBase.init;begin // do nothing here;end;procedure TfrBase.loadData;begin //do nothing here;end;procedure TfrBase.MMmciNotify(var Msg: TMessage);begin if Msg.WParam = mci_Notify_Successful then begin delay(300); inc(vfIndex); if vfIndex<=voiceFiles.Count-1 then playMp3(voiceFiles[vfIndex], handle) else begin Delay(500); Next; end; end;end;procedure TfrBase.Next;begin //do nothing here;end;procedure TfrBase.setBtVisible(value: boolean);var i: integer;begin if Buttons<>nil then begin if value then for i:= 0 to buttons.Count-1 do TControl(buttons.Items).Visible:=value else for i:= buttons.Count-1 downto 0 do TControl(buttons.Items).Visible:=value; end;end;procedure TfrBase.settingColors;var i, j: integer;begin color:=clBegin; for i:=0 to ComponentCount-1 do begin if Components is TsrToolButton then begin TsrToolButton(Components).clBegin:=clBegin; TsrToolButton(Components).clEnd:=clEnd; TsrToolButton(Components).clslBegin:=clslBegin; TsrToolButton(Components).clslEnd:=clslEnd; TsrToolButton(Components).clhotLine:=clslEnd; end; if Components is TmsgView then begin TmsgView(Components).clTitleBegin:=clBegin; TmsgView(Components).clTitleEnd:=clEnd; TmsgView(Components).clSelected:=clslEnd; for j:=0 to TmsgView(Components).Columns.Count-1 do if j mod 2 = 0 then TmsgView(Components).Columns.Items[j].Color:=clEnd; end; if Components is TsrPanel then begin TsrPanel(Components).BeginColor:=clEnd; TsrPanel(Components).EndColor:=clBegin; TsrPanel(Components).FrameColor:=clEnd; end; end;end;procedure TfrBase.wmActive(var Msg: TMessage);begin application.ProcessMessages; loadData;end;{ TwsTabSheet }end.
 
看我这个,用rztabs的。unit INXITEUnit;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ImgList, ActnList, ADODB, ShellAPI, MainUnit, ComCtrls, Menus, ExtCtrls, RzPanel, RzSplit, RzGroupBar, RzTabs, DB, //新增加的FrameUnit列在这儿 USRTOOLSEDTFRAMEUnit, AUTOJOBUnit, BaseFrameUnit, TblClassUnit, TblQueryFrameUnit, GKDataFrameUnit, TblRecordQueryFrameUnit, UserGroupManagerFrameUnit, TblRecordEditFrameUnit // ;type TINXITEForm = class(TForm) ilINXITE: TImageList; actlstINXITE: TActionList; actTBCX: TAction; actTBPL: TAction; actYTZSD: TAction; actZTGKMK: TAction; actJK: TAction; actDSRWPZ: TAction; ActCloseActivePage: TAction; actCloseAllPage: TAction; actExit: TAction; statINXITE: TStatusBar; mmINXITE: TMainMenu; N1: TMenuItem; N2: TMenuItem; N3: TMenuItem; N4: TMenuItem; N5: TMenuItem; N6: TMenuItem; NTools: TMenuItem; N7: TMenuItem; NHelp: TMenuItem; rzszpnlLeft: TRzSizePanel; rzgrpbrLeft: TRzGroupBar; rzgrp1: TRzGroup; rzgrp2: TRzGroup; rzgrp3: TRzGroup; rzpgcntrlINXITE: TRzPageControl; actTYGJPZ: TAction; qryEdit: TADOQuery; { Private declarations } procedure SelectPage(PageIdx: Integer); procedure NewPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = ''); // procedure CloseAll; procedure actExitExecute(Sender: TObject); //关闭所有Frame窗口 procedure INXITEActExecute(Sender: TObject); //执行打开Frame操作 procedure INXITEToolsMenuItemClick(Sender: Tobject); //通用工具菜单点击 procedure actCloseAllPageExecute(Sender: TObject); //关闭所有Frame procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure ActCloseActivePageExecute(Sender: TObject); //关闭当前Frame procedure SetINXITEPriv; //设置Action的Enable procedure AddToolsMenu; procedure FormActivate(Sender: TObject); procedure rzpgcntrlINXITEClose(Sender: TObject; var AllowClose: Boolean); //设置Tools菜单的Item procedure DelPage(strTitle: string); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); public { Public declarations } procedure AddPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = ''); procedure ClosePage(strtitle: string); end;var INXITEForm: TINXITEForm; PageList: TStringList; //声明的Frame变量加在这儿 UsrToolsEdtFrame: TUSRTOOLSEDTFrame; AutoJobFrame: TAUTOJOBFrame; TblClassFrame: TTBLClassFrame; TblQueryFrame: TTBLQueryFrame; GKDataFrame: TGKDataFrame; tmpTblRecordQueryFrame: TTblRecordQueryFrame; UserGroupManagerFrame: TUserGroupManagerFrame; tmpTblRecordEditFrame: TTblRecordEditFrame; //implementation{$R *.dfm}{ TINXITEForm }procedure TINXITEForm.AddPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = '');var PageIdx: integer;begin//增加页面 PageIdx := PageList.IndexOf(strTitle); if PageIdx <> -1 then SelectPage(PageIdx) else NewPage(strTitle, AddRecord, FSQL, FGUID);end;procedure TINXITEForm.CloseAll;var PageIdx: integer;begin//在这儿释放所有的Frame,并删除TabSheet for PageIdx := rzpgcntrlINXITE.PageCount - 1 downto 0 do DelPage(rzpgcntrlINXITE.Pages[PageIdx].Caption);end;procedure TINXITEForm.DelPage(strTitle: string);var PageIdx, ObjectIdx: integer; tmpTab: TRzTabSheet;begin//关闭页面,先清空Frame,再删除TabSheet对象 PageIdx := PageList.IndexOf(strTitle); if PageIdx <> -1 then begin tmpTab := (PageList.Objects[PageIdx] as TRzTabSheet); for ObjectIdx := tmpTab.ControlCount - 1 downto 0 do begin //先调用FreeAll来清空一些动态建立的资源 if strTitle = '通用工具配置' then USRTOOLSEDTFrame.FreeAll; if strTitle = '定时任务配置' then AUTOJOBFrame.FreeAll; if strTitle = '库表分类' then TblClassFrame.FreeAll; if strTitle = '库表查询' then TblQueryFrame.FreeAll; if strTitle = '逐条公开模块' then GKDataFrame.FreeAll; if pos('表记录查询', strTitle) > 0 then begin tmpTblRecordQueryFrame := (tmpTab.Controls[ObjectIdx] as TTblRecordQueryFrame); tmpTblRecordQueryFrame.FreeAll; end; if pos('表记录编辑', strTitle) > 0 then begin tmpTblRecordEditFrame := (tmpTab.Controls[ObjectIdx] as TTblRecordEditFrame); tmpTblRecordEditFrame.FreeAll; //这儿要做一些记录的定位处理,查找原来的表记录查询窗口,并定位等操作 end; if strTitle = '用户组设定' then UserGroupManagerFrame.FreeAll; (tmpTab.Controls[ObjectIdx] as TControl).Free; end; tmpTab.Free; PageList.Delete(PageIdx); end;end;procedure TINXITEForm.NewPage(strTitle: string; AddRecord: Boolean = False; FSQL: string = ''; FGUID: string = '');var NewTab: TRzTabSheet;begin NewTab := nil; if strTitle = '通用工具配置' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := '通用工具配置'; NewTab.PageControl := rzpgcntrlINXITE; USRTOOLSEDTFrame := TUSRTOOLSEDTFrame.Create(Application); USRTOOLSEDTFrame.Parent := NewTab; USRTOOLSEDTFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; UsrToolsEdtFrame.Init; end; if strTitle = '定时任务配置' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; AutoJobFrame := TAUTOJOBFrame.Create(Application); AutoJobFrame.Parent := NewTab; AutoJobFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; AutoJobFrame.Init; end; if strTitle = '库表分类' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; TblClassFrame := TTBLClassFrame.Create(Application); TblClassFrame.Parent := NewTab; TblClassFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; TblClassFrame.Init; end; if strTitle = '库表查询' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; TblQueryFrame := TTBLQueryFrame.Create(Application); TblQueryFrame.Parent := NewTab; TblQueryFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; TblQueryFrame.Init; end; if strTitle = '逐条公开模块' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; GkDataFrame := TGKDataFrame.Create(Application); GKDataFrame.Parent := NewTab; GKDataFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; GKDataFrame.Init; end; if pos('表记录查询', strTitle) > 0 then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; tmpTblRecordQueryFrame := TTblRecordQueryFrame.Create(Application); tmpTblRecordQueryFrame.Parent := NewTab; tmpTblRecordQueryFrame.Align := alClient; tmpTblRecordQueryFrame.Name := 'Qry' + copy(strTitle, 11, Length(strTitle)); rzpgcntrlINXITE.ActivePage := NewTab; tmpTblRecordQueryFrame.FrameCaption := strTitle; tmpTblRecordQueryFrame.TableName := copy(strTitle, 11, Length(strTitle)); tmpTblRecordQueryFrame.Init; end; if Pos('表记录编辑', strTitle) > 0 then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; tmpTblRecordEditFrame := TTblRecordEditFrame.Create(Application); tmpTblRecordEditFrame.Parent := NewTab; tmpTblRecordEditFrame.Align := alClient; tmpTblRecordEditFrame.Name := 'Edt' + copy(strTitle, 11, Length(strTitle)); rzpgcntrlINXITE.ActivePage := NewTab; tmpTblRecordEditFrame.FrameCaption := strTitle; tmpTblRecordEditFrame.TableName := copy(strTitle, 11, Length(strTitle)); tmpTblRecordEditFrame.AddRecord := AddRecord; //新增 true 编辑 false tmpTblRecordEditFrame.GUID := FGUID; //定位GUId tmpTblRecordEditFrame.SQL := FSQL; //SQL语句 tmpTblRecordEditFrame.Init; end; if strTitle = '用户组设定' then begin NewTab := TRzTabSheet.Create(rzpgcntrlINXITE); NewTab.Caption := strTitle; NewTab.PageControl := rzpgcntrlINXITE; UserGroupManagerFrame := TUserGroupManagerFrame.Create(Application); UserGroupManagerFrame.Parent := NewTab; UserGroupManagerFrame.Align := alClient; rzpgcntrlINXITE.ActivePage := NewTab; UserGroupManagerFrame.Init; end; if NewTab <> nil then PageList.AddObject(strTitle, NewTab);end;procedure TINXITEForm.SelectPage(PageIdx: Integer);var ActivePage: TRzTabSheet;begin// if PageList.Objects[PageIdx] <> nil then begin ActivePage := (PageList.Objects[PageIdx] as TRzTabSheet); rzpgcntrlINXITE.ActivePage := ActivePage; end;end;procedure TINXITEForm.actExitExecute(Sender: TObject);begin CloseAll; Close;end;procedure TINXITEForm.INXITEActExecute(Sender: TObject);begin AddPage((Sender as TAction).Caption);end;procedure TINXITEForm.INXITEToolsMenuItemClick(Sender: Tobject);begin if FileExists((Sender as TMenuItem).Hint) then ShellExecute(handle, 'open', pchar((Sender as TMenuItem).Hint), '', '', SW_SHOW) else ShowMessage('可执行文件不存在,请通知系统管理员!!!');end;procedure TINXITEForm.actCloseAllPageExecute(Sender: TObject);begin CloseAll;end;procedure TINXITEForm.FormCreate(Sender: TObject);begin PageList := TStringList.Create;end;procedure TINXITEForm.FormDestroy(Sender: TObject);begin PageList.Free;end;procedure TINXITEForm.ActCloseActivePageExecute(Sender: TObject);begin ClosePage(rzpgcntrlINXITE.ActivePage.Caption);end;procedure TINXITEForm.SetINXITEPriv;var GrpPrivLst: TStringList; GrpPriv: string; i: Integer; clsName: string;begin//根据用户权限,设置INXITE主界面上的可操作项 GrpPrivLst := TStringList.Create; qryEdit.Close; qryEdit.SQL.Text := 'SELECT A.GUIPRIV FROM' + ' USR_GROUP A,GAZX30USER B' + ' WHERE B.USERNAME=''' + MainForm.G_CZY + '''' + ' AND B.GRPPRIV=A.T_USR_GROUP_NAME'; qryEdit.Open; GrpPriv := qryEdit.FieldByName('GUIPRIV').AsString; MainForm.SplitString(GrpPriv, ',', GrpPrivLst); for i := 0 to INXITEForm.ComponentCount - 1 do if INXITEForm.Components.Tag > 0 then begin clsName := INXITEForm.Components.ClassName; if clsName = 'TAction' then (INXITEForm.Components as TAction).Enabled := (GrpPrivLst.IndexOf((INXITEForm.Components as TAction).Caption) <> -1) end; for i := 0 to NTools.Count - 1 do NTools.Items.Enabled := (GrpPrivLst.IndexOf(NTools.Items.Caption) <> -1); GrpPrivLst.Free;end;procedure TINXITEForm.AddToolsMenu;var tmpAdoQuery: TADOQuery; i: Integer; tmpMenuItem: TMenuItem;begin//根据用户权限,生成用户可使用的通用工具列表//先清空Tools菜单 for i := NTools.Count - 1 downto 0 do NTools.Items.Free;//再生成Tools菜单 tmpAdoQuery := TADOQuery.Create(nil); tmpAdoQuery.Connection := MainForm.UserADOConnection; tmpAdoQuery.SQL.Text := 'SELECT TOOLNAME,TOOLFILENAME FROM USR_TOOLS WHERE ENABLED=1'; tmpAdoQuery.Open; while not tmpAdoQuery.Eof do begin tmpMenuItem := TMenuItem.Create(nil); tmpMenuItem.Caption := tmpAdoQuery.fieldbyname('TOOLNAME').AsString; tmpMenuItem.Hint := tmpAdoQuery.fieldByname('TOOLFILENAME').AsString; tmpMenuItem.Tag := 1; tmpMenuItem.OnClick := INXITEToolsMenuItemClick; NTools.Add(tmpMenuItem); tmpAdoQuery.Next; end; tmpAdoQuery.Close; FreeAndNil(tmpAdoQuery);end;procedure TINXITEForm.FormActivate(Sender: TObject);begin statINXITE.Panels[1].Text := MainForm.G_CZY; AddToolsMenu; SetINXITEPriv;end;procedure TINXITEForm.rzpgcntrlINXITEClose(Sender: TObject; var AllowClose: Boolean);begin ActCloseActivePageExecute(Self);end;procedure TINXITEForm.ClosePage(strtitle: string);begin DelPage(strtitle); if rzpgcntrlINXITE.PageCount > 0 then rzpgcntrlINXITE.ActivePageIndex := rzpgcntrlINXITE.PageCount - 1;end;procedure TINXITEForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);begin CloseAll; CanClose := True;end;end.
 
好东西,正好要用到,收藏了!
 
如何在Tab上增加一个关闭按钮图标呢?
 
请教honghs大侠:1、如何在Tab上增加一个关闭按钮图标呢? 2、换成一般的tform,在做成MDI模式,怎么显示出窗体?望赐教!多谢~!
 
动态创建倒是理解的,就是不理解那个框架到底怎么用法
 
期待高手回答~!
 
还是苦无良策,望高手指点~!
 
MDI的难度很高啊。我也没搞定。所以用了FRAME你可以到DFW QQ群 3401260中找Inxite.rar。
 
继承呗。从TTabSheet继承,生一个TTabWebSheet(TTWS)。不从TTabSheet的父类中继承是因为TPageControl的Pages是TTabSheet类型的。然后继承TPageControl,生一个TWebPageControl,让她生成TTWS的标签页。然后每需要一个标签页就动态生成一个TTWS。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部