使用Panel的OnMouseDown或OnMouseUp事件

解决方案 »

  1.   

    SHW014的说法对于直接点击PANEL显示各个PANEL名称是可以的但是对先显示POPUPMENU后在菜单选项中实现仍是不可行的.
      

  2.   

    在OnMouseDown或OnMouseUp事件中记录下是哪一个PANEL(用变量)
    在POPUPMENU中检查该变量
      

  3.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ExtCtrls, Menus;type
      TForm1 = class(TForm)
        Button1: TButton;
        Panel1: TPanel;
        Edit1: TEdit;
        PopupMenu1: TPopupMenu;
        Panel2: TMenuItem;
        procedure FormCreate(Sender: TObject);
        procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);  {如果有静态PANEL则放在这里,否则的话放在public}
        procedure Panel2Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      PPanel: ^TPanel;
      name1:string;
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin new(PPanel);
       PPanel^:=TPanel.create(self);
       PPanel^.OnMouseUp:=Panel1MouseUp;{指定Panel的OnMouseUp事件}
       PPanel^.PopupMenu:=PopupMenu1;   
       PPanel^.caption:='PPanel';
       InsertControl(PPanel^);end;procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
    name1:=TPanel(Sender).Caption;  {将标题保存到变量name1}
    end;procedure TForm1.Panel2Click(Sender: TObject); {菜单第一项的单击事件}
    begin
      Edit1.Text:=name1;            {在编辑框中显示您要的变量}
    end;end.
      

  4.   

    shw014的方法可行,不过可以不用指针,Delphi中的对象本来就是指针,所以可以用Tpanel代替^TPanel。
      

  5.   

    shw014的方法非常对,请问如何将分数给你?