mdichildform子窗体显示如何自动隐藏主窗体mdiform的工具栏???
解决方案 »
- 若干EDIT,如何得到第一个和最后一个?
- 如何让button1 button2接收拖拽?
- 求救:关于Query中SQL实现两表的连接查询问题?
- 两个小问题,多谢帮忙。
- 简单问题,困扰我,ENTER键回车
- 求求各位兄弟姐妹,socket我实在有点迷糊了,能不能帮我看看程序。在线等待
- 请问如何实现选择edit1中的内容,按f1,可以调用自己编写的帮助文件?
- 請問如何在Win98下用Delphi的ADO系列組件
- 如何正确解析Http 请求返回流,变成字符串
- 怎样从EXCEL中把一个字段的数据倒入一个memo里?
- 做Delphi三年了,现在dotnet大行其道,要不要转到C# net呢?不知所措!
- 关于输入法的问题,急!在线等!
这样最大化后子窗体的工具栏显示在主窗体最上面了要不然你用寻找同名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来进行。