我想做一个停靠菜单,就象Delphi的IDE里的菜单那样。我用下面的
方法试了,能行,但是有问题。1. Assume there is a main menu on the form, let me name it MainMenu
2. Set both MainMenu.AutoHotkeys and MainMenu.AutoLineReduction to 
maManual
3. Put a toolbar on the coolbar, let me name it tbMenu
4. Set tbMenu.Menu to MainMenu
5. Clear the form's Menu property问题在于如果这个窗体是MDIForm的,它的子窗体最大化后看不到
有上角的3个按钮,我就没法最小化它。请问应该如何做呢?谢谢!

解决方案 »

  1.   

    只要没有主菜单的MDIForm,就有你说的这个现象。
      

  2.   

    给一个从TToolbar派生的控件,自动完成和主菜单的关联!unit MenuBar;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ToolWin, ComCtrls, Menus;type
      TMenuBar = class(TToolBar)
      private
        FMenu: TMainMenu;
        procedure SetMenu(const Value: TMainMenu);
      public
        constructor Create(AOwner: TComponent); override;
      published
        property EdgeBorders default [];
        property Menu: TMainMenu read FMenu write SetMenu;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('Samples', [TMenuBar]);
    end;{ TMenuBar }constructor TMenuBar.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      Flat := True;
      ShowCaptions := True;
      EdgeBorders := [];
      ControlStyle := [csCaptureMouse, csClickEvents, csMenuEvents, csSetCaption];
    end;procedure TMenuBar.SetMenu(const Value: TMainMenu);
    var
      i: Integer;
      Button: TToolButton;
    begin
      if FMenu = Value then exit;
      if Assigned(FMenu) then
        for i := ButtonCount - 1 downto 0 do
          Buttons[i].Free;
      FMenu := Value;
      if not Assigned(FMenu) then exit;
      for i := ButtonCount to FMenu.Items.Count - 1 do
      begin
        Button := TToolButton.Create(Self);
        try
          Button.AutoSize := True;
          Button.Grouped := True;
          Button.Parent := Self;
          Buttons[i].MenuItem := FMenu.Items[i];
        except
          Button.Free;
          raise;
        end;
      end;
      for i := 0 to FMenu.Items.Count - 1 do
        Buttons[i].MenuItem := FMenu.Items[i];
    end;end.配合CoolBar使用
    CoolBar.DockSite:=True
    MenuBar.DragKind:=dkDock
    MenuBar.DragMode:=dmAutomatic
    MainMenu.AutoMerge:=True
      

  3.   

    to ehom(?!) :
    1. TToolBar自己已经有一个Menu属性了(我用的是Delphi 6)
    2.没有直接使用你的代码,但参考你的代码做相应的设置,没有解决我的问题
    不管怎样,先谢谢你。
      

  4.   

    Delphi引入了一些新特征。Docking 就是其中的一项,有人将Docking译为对接、入坞、结合等,也可以译为“窗口融合技术”。那么什么是窗口融合技术呢?窗口融合是一项先进的界面设计技术,体现了当今的发展趋势。Word97的浮动工具栏就是一种窗口融合技术,有时也称为Word97风格的浮动工具栏。下面针对目前比较流行的窗口与窗口的融合例程来进行:
      经过笔者一段时间的使用,发现Panel控件最适合作两个窗口融合的工具。由于这是最一般的情况,所以这里举一个具有代表性的例子详细说明。我们要达到的要求是:程序运行后,出现主窗口,按一个按钮,出现另一个窗口,拖动此窗口,与主窗口融合在一起,融合后主窗口的Caption变成两个窗口的Caption相加。在主窗口form1中放置两个Panel控件(panel1和panel2),一个Button控件(button1);另一个窗口form2为空白窗口。具体属性设置如下:  panel1:
      align:alleft;
      docksite:true;
      usedockmanager:true;
      panel2:
      align:albottom;
      docksite:true;
      usemanager:true;
      form2:
      anchors:[aktop,akbottom,akleft,akright];
      dragmode:dmautomatic;
      dragkind:dkdock;
      设置button1的onclick事件,对应的代码如下:
      procedure TForm1.Button1Click(Sender: TObject);
      begin
      form2.Show;
      a:=form1.caption;
      b:=form2.caption;
      end;
      设置panel1和panel2的onundock事件,代码如下:
      procedure TForm1.Panel1UnDock(Sender: TObject; Client: TControl; NewTarget: TWinControl; var Allow: Boolean);  begin
      form1.caption:=a;
      form1.Refresh;
      end;
      设置panel1和panel2的ondockdrop事件,代码如下:
      procedure TForm1.Panel1DockDrop(Sender:TObject; Source: TDragDockObject; X, Y: Integer);
      begin
      form1.Caption:=a+′,′+b;
      form1.Refresh;
      end;
      其中a,b为String型变量,用以保存窗口的最初标题,在form1的接口处声明。
    //转载