如题,MENUE如下,动态创建
a--aa
b
c--cc
d
e--ee0
 --ee1
 --ee2
f
差不多是这个样子了

解决方案 »

  1.   

    一个例子:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Menus;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
        APopup : TPopupMenu;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    begin
      APopup := TPopupMenu.Create(Self);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
      APopup.Free;
    end;procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    var
      AItem   : TMenuItem;
      ASubItem: TMenuItem;
      APoint  : TPoint;
    begin
      if Button = mbRight then
      begin
        APopup.Items.Clear;    AItem := TMenuItem.Create(Self);
        AItem.Caption := 'a';
        APopup.Items.Add(AItem);
        ASubItem := TMenuItem.Create(Self);
        ASubItem.Caption := 'aa';
        AItem.Add(ASubItem);    AItem := TMenuItem.Create(Self);
        AItem.Caption := 'b';
        APopup.Items.Add(AItem);    AItem := TMenuItem.Create(Self);
        AItem.Caption := 'c';
        APopup.Items.Add(AItem);
        ASubItem := TMenuItem.Create(Self);
        ASubItem.Caption := 'cc';
        AItem.Add(ASubItem);    AItem := TMenuItem.Create(Self);
        AItem.Caption := 'd';
        APopup.Items.Add(AItem);    AItem := TMenuItem.Create(Self);
        AItem.Caption := 'e';
        APopup.Items.Add(AItem);
        ASubItem := TMenuItem.Create(Self);
        ASubItem.Caption := 'ee0';
        AItem.Add(ASubItem);
        ASubItem := TMenuItem.Create(Self);
        ASubItem.Caption := 'ee1';
        AItem.Add(ASubItem);
        ASubItem := TMenuItem.Create(Self);
        ASubItem.Caption := 'ee2';
        AItem.Add(ASubItem);    GetCursorPos(APoint);
        APopup.Popup(APoint.X, APoint.Y);
      end;
    end;end.