TPopupMenu作为子组件,不起作用

时间:2019-01-29 14:56:47

标签: delphi components dropdownbutton subcomponent

我正在尝试开发一个组件,特别是链接到弹出菜单的按钮。 我不明白为什么我看不到PopupMenu。

下面是我的代码:

unit DropDownButton;

    interface

    uses
      System.SysUtils,
      System.Classes,
      Vcl.Controls,
      Vcl.StdCtrls,
      System.Types,
      Vcl.Menus;

    type
      TDropDownButton = class;

      TDropDownButton = class(TButton)
      private
        FDropDownMenu: TPopupMenu;
      protected
      public
        constructor Create(AOwner: TComponent); override;
        procedure Click; override;
      published
        property DropDownMenu: TPopupMenu read FDropDownMenu;
      end;

    procedure Register;

    implementation

    procedure Register;
    begin
      RegisterComponents('Flexline', [TDropDownButton]);
    end;

    constructor TDropDownButton.Create(AOwner: TComponent);
    begin
      inherited Create(AOwner);
      FDropDownMenu:= TPopupMenu.Create(Self);
      FDropDownMenu.Name:= 'Menu';
      FDropDownMenu.SetSubComponent(True);
    end;

    procedure TDropDownButton.Click;
    var
      _point: TPoint;
    begin
      _point:= Self.ClientToScreen(Point(0,0));
      FDropDownMenu.Popup(_point.X,_point.Y + Height);
      inherited Click;
    end;

    end.

谢谢。

我想在我的项目中使用一个下拉按钮

0 个答案:

没有答案