请问DELHPI,中能否做到像WINDOWS一样的菜单拖动效果,我发现POPUPMENU和MAINMENU都没有拖动事件,请问各位朋友能做到吗。

解决方案 »

  1.   

    DELPHI中的,TMainMenu和TPopUpMenu都是不可视控件,不可视控件可以移动吗?当然不行!有空看看代码Menus单元的代码,类只不过是封装了关于菜单的API,而和菜单本身无关!想要移动当然只能是可视控件!找个能显示下拉菜单的载体(如TToolBar),把默认的菜单隐藏!
      

  2.   

    非常感谢ehom(?!) 兄的热情支持
    但小弟水平巨臭,能否给出一个例子参考
    在菜单上的拖动,比如两个菜单的Item 能够交换位子
    犹如WIndows开始菜单一样
      

  3.   

    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);
      protected
        procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
      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;constructor TMenuBar.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      Flat := True;
      ShowCaptions := True;
      EdgeBorders := [];
      ControlStyle := [csCaptureMouse, csClickEvents, csMenuEvents, csSetCaption];
    end;procedure TMenuBar.GetChildren(Proc: TGetChildProc; Root: TComponent);
    begin
    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.现成控件会用吗?加上TCoolBar如果要移出为窗体,找Dock相关资料看
      

  4.   

    啊?理解错误!Window开始菜单啊,呵呵,上当了,那根本就不是传统意义上的菜单!看看它的CLASS,ToolBarWindow32!用普通菜单是做不到的!
      

  5.   

    不管怎么,还是很谢谢ehom兄了,我会另开贴子给分的,来接喔!