关于动态控件中运用右键菜单的问题,请高手指点. 使用Panel的OnMouseDown或OnMouseUp事件 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 SHW014的说法对于直接点击PANEL显示各个PANEL名称是可以的但是对先显示POPUPMENU后在菜单选项中实现仍是不可行的. 在OnMouseDown或OnMouseUp事件中记录下是哪一个PANEL(用变量)在POPUPMENU中检查该变量 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);beginname1:=TPanel(Sender).Caption; {将标题保存到变量name1}end;procedure TForm1.Panel2Click(Sender: TObject); {菜单第一项的单击事件}begin Edit1.Text:=name1; {在编辑框中显示您要的变量}end;end. shw014的方法可行,不过可以不用指针,Delphi中的对象本来就是指针,所以可以用Tpanel代替^TPanel。 shw014的方法非常对,请问如何将分数给你? 发一个Bpl框架2.0(for D7),欢迎接分... Delphi2007没有代码编辑全屏功能? createwindow出的edit不能获得tab键的困惑 执行dll中的对话框?? 【我是菜鸟】请问如何做出自动隐藏(/自动伸缩/自动依靠)的效果,类似MS7.0集成开发界面 怎么更改DBgride中的数据? 求天心企业全能管理系统的技术资料(Delphi开发) 谢谢,帮帮忙 关于COMBOBOX的问题 搞数据库不会打印真是一大失误! 谁能给我解答么??一个菜鸟问题 这个问题怎么办呢?关于Query的字符串属性??
在POPUPMENU中检查该变量
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.