mdichildform子窗体显示如何自动隐藏主窗体的工具栏???
2008-12-11 10:07
459 查看
mdichildform子窗体显示如何自动隐藏主窗体的工具栏??? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061220145944198.html
mdichildform子窗体显示如何自动隐藏主窗体mdiform的工具栏???
???
每个子窗体作上工具栏。
这样最大化后子窗体的工具栏显示在主窗体最上面了。。。
要不然你用寻找同名Action的方式也可以作到。
举个示例代码:
// 当主窗体的主工具栏按钮按下时去寻找子窗体中同名的Action并执行
procedure TfrmMain.BindActiveFormExecute(Sender: TObject);
var
ActiveForm: TForm;
Action: TAction;
begin
Action := nil;
// 判断当前页是否有停靠窗口
if (PageControl1.PageCount > 0) and
(PageControl1.ActivePage.ControlCount > 0) and
(PageControl1.ActivePage.Controls[0] is TForm) then
begin
ActiveForm := PageControl1.ActivePage.Controls[0] as TForm;
// 寻找当前Action
if Sender is TAction then Action := FindSameAction(ActiveForm, Sender as TAction);
end;
// 执行绑定过程
if Assigned(Action) then Action.Execute;
end;
// 更新主窗体的Action的Enabled有效性
procedure TfrmMain.BindActiveFormUpdate(Sender: TObject);
var
ActiveForm: TForm;
MainAction, Action: TAction;
begin
Action := nil;
// 寻找当前快捷菜单的Active
if (PageControl1.PageCount > 0) and
(PageControl1.ActivePage.ControlCount > 0) and
(PageControl1.ActivePage.Controls[0] is TForm) then
begin
ActiveForm := PageControl1.ActivePage.Controls[0] as TForm;
Action := FindSameAction(ActiveForm, Sender as TAction);
end;
if Assigned(Action) then
begin
Action.Update;
MainAction := (Sender as TAction);
// 设置Action属性
MainAction.Enabled := Action.Enabled;
if Action.Caption <> MainAction.Caption then Action.Caption := MainAction.Caption;
if Action.ShortCut <> MainAction.ShortCut then Action.ShortCut := MainAction.ShortCut;
end else (Sender as TAction).Enabled := False;
end;
// 在子窗体中寻找同名的Action
function TfrmMain.FindSameAction(Form: TForm; Action: TAction): TAction;
var
ActionList: TActionList;
i, j: Integer; //临时增加
frmSub: TForm; //临时增加
begin
Result := nil;
ActionList := nil;
//ActionList := TActionList.Create(nil); // 基本没用
try
// 循环枚举窗口上的所有元素
for i := 0 to Form.ComponentCount - 1 do
begin
// 判断是否是子窗口
if Form.Components[i] is TForm then
begin
frmSub := (Form.Components[i] as TForm); //记录窗体子元件
// 循环查找子窗口中的TActionList
for j:=0 to frmSub.ComponentCount - 1 do
begin
if frmSub.Components[j] is TActionList then
begin
ActionList := frmSub.Components[j] as TActionList;
Break;
end;
end;
end;
// 判断寻找到的控件是否是TActionList
if Form.Components[i] is TActionList then
begin
ActionList := Form.Components[i] as TActionList;
Break;
end;
end;
// 没有找到退出过程
if Assigned(ActionList) then
begin
// 循环查找对应的Action
for i := 0 to ActionList.ActionCount - 1 do
begin
if (ActionList[i] as TAction).Name = Action.Name then
begin
Result := ActionList[i] as TAction;
Break;
end;
end;
end;
finally
//ActionList.Free; // 基本没用
end;
end;
主窗体里的ActionList里的Action的onExecute 绑定BindActiveFormExecute函数,那当子窗体打开后点主窗体的工具栏就会去找同名的action执行它的onexecute
而Onupdate应该绑定BindActiveFormUpdate过程,这样实现主窗体的工具栏按钮有效性跟据子窗体同名action来进行。
http://www.delphi2007.net/DelphiDB/html/delphi_20061220145944198.html
mdichildform子窗体显示如何自动隐藏主窗体mdiform的工具栏???
???
每个子窗体作上工具栏。
这样最大化后子窗体的工具栏显示在主窗体最上面了。。。
要不然你用寻找同名Action的方式也可以作到。
举个示例代码:
// 当主窗体的主工具栏按钮按下时去寻找子窗体中同名的Action并执行
procedure TfrmMain.BindActiveFormExecute(Sender: TObject);
var
ActiveForm: TForm;
Action: TAction;
begin
Action := nil;
// 判断当前页是否有停靠窗口
if (PageControl1.PageCount > 0) and
(PageControl1.ActivePage.ControlCount > 0) and
(PageControl1.ActivePage.Controls[0] is TForm) then
begin
ActiveForm := PageControl1.ActivePage.Controls[0] as TForm;
// 寻找当前Action
if Sender is TAction then Action := FindSameAction(ActiveForm, Sender as TAction);
end;
// 执行绑定过程
if Assigned(Action) then Action.Execute;
end;
// 更新主窗体的Action的Enabled有效性
procedure TfrmMain.BindActiveFormUpdate(Sender: TObject);
var
ActiveForm: TForm;
MainAction, Action: TAction;
begin
Action := nil;
// 寻找当前快捷菜单的Active
if (PageControl1.PageCount > 0) and
(PageControl1.ActivePage.ControlCount > 0) and
(PageControl1.ActivePage.Controls[0] is TForm) then
begin
ActiveForm := PageControl1.ActivePage.Controls[0] as TForm;
Action := FindSameAction(ActiveForm, Sender as TAction);
end;
if Assigned(Action) then
begin
Action.Update;
MainAction := (Sender as TAction);
// 设置Action属性
MainAction.Enabled := Action.Enabled;
if Action.Caption <> MainAction.Caption then Action.Caption := MainAction.Caption;
if Action.ShortCut <> MainAction.ShortCut then Action.ShortCut := MainAction.ShortCut;
end else (Sender as TAction).Enabled := False;
end;
// 在子窗体中寻找同名的Action
function TfrmMain.FindSameAction(Form: TForm; Action: TAction): TAction;
var
ActionList: TActionList;
i, j: Integer; //临时增加
frmSub: TForm; //临时增加
begin
Result := nil;
ActionList := nil;
//ActionList := TActionList.Create(nil); // 基本没用
try
// 循环枚举窗口上的所有元素
for i := 0 to Form.ComponentCount - 1 do
begin
// 判断是否是子窗口
if Form.Components[i] is TForm then
begin
frmSub := (Form.Components[i] as TForm); //记录窗体子元件
// 循环查找子窗口中的TActionList
for j:=0 to frmSub.ComponentCount - 1 do
begin
if frmSub.Components[j] is TActionList then
begin
ActionList := frmSub.Components[j] as TActionList;
Break;
end;
end;
end;
// 判断寻找到的控件是否是TActionList
if Form.Components[i] is TActionList then
begin
ActionList := Form.Components[i] as TActionList;
Break;
end;
end;
// 没有找到退出过程
if Assigned(ActionList) then
begin
// 循环查找对应的Action
for i := 0 to ActionList.ActionCount - 1 do
begin
if (ActionList[i] as TAction).Name = Action.Name then
begin
Result := ActionList[i] as TAction;
Break;
end;
end;
end;
finally
//ActionList.Free; // 基本没用
end;
end;
主窗体里的ActionList里的Action的onExecute 绑定BindActiveFormExecute函数,那当子窗体打开后点主窗体的工具栏就会去找同名的action执行它的onexecute
而Onupdate应该绑定BindActiveFormUpdate过程,这样实现主窗体的工具栏按钮有效性跟据子窗体同名action来进行。
相关文章推荐
- iphone自动隐藏和显示工具栏和导航条
- iphone自动隐藏和显示工具栏和导航条
- [VB.NET]请问类似QQ窗体靠边自动隐藏的效果如何实现?????
- Framework7跳转页面如何自动隐藏工具栏(no-tabbar)
- iphone里如何实现像图片浏览那样的自动隐藏和导航条和工具栏
- C# 屏幕监控 自动截屏程序 主窗体隐藏,仅在进程中显示
- 如何实现:GridView 控件中显示的文本不自动换行,隐藏超出宽度部分wj-wangjun
- iphone自动隐藏和显示工具栏和导航条
- iphone自动隐藏和显示工具栏和导航条
- 在mfc中,如何设置一个隐藏菜单栏,工具栏,状态栏,最大化、最小化、关闭按钮的窗体 分类: MFC
- 在mfc中,如何设置一个隐藏菜单栏,工具栏,状态栏,最大化、最小化、关闭按钮的窗体
- C# 屏幕监控 自动截屏程序 主窗体隐藏,仅在进程中显示
- ExtJS4如何自动生成控制grid的列显示、隐藏的checkbox
- 如何设置table,使单元格内容无论多少,只显示一行,超过单元格宽度的部分自动隐藏,当鼠标放到单元格上,内容自动显示完整?
- <span>中显示文字超出宽度如何自动隐藏
- 如何实现窗体跟随另一个程序一起显示,一起隐藏!!
- Xcode 5.0.2 如何显示、隐藏运行调试工具栏
- C# 屏幕监控 自动截屏程序 主窗体隐藏,仅在进程中显示
- [Delphi]让窗体感知鼠标的进入与移出并自动隐藏与显示窗口