1

英文翻译(已经有一段时间了,所以可能不完全准确;使用谷歌翻译我遇到问题的部分):

我正在使用 Delphi 中的一个可视组件(它不是标准的 Delphi 组件),它拥有一个名为PopupMenu. 我将组件中的属性PopupMenu与 PopupMenu 相关联,但是当我单击 [鼠标] 的右键时,我什么也看不到。

我还尝试使用以下代码强制它显示:

x:= Mouse.CursorPos.X; 
y:= Mouse.CursorPos.Y; 
// //showmessage(inttostr(x)) PopupMenu1.Popup(x,y);

我有两个问题:

怎么知道鼠标右键是激活的?你们有没有遇到过这种类型的问题?谢谢您的回答。

谢谢

编辑

这是我用来执行该过程的PopupMenu1:过程

TForm6.GeckoBrowser1DOMMouseDown(Sender: TObject; Key: Word); 
var x,y:integer; 
begin 
  if key=VK_RBUTTON then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y; 
    //showmessage(inttostr(x)) PopupMenu1.Popup(x,y); 
  end; 
end;
4

1 回答 1

0

这永远不会奏效。您不能将表单中的代码与组件代码混合在一起。

我会建议这样的事情:

interface

type
  TGeckoBrowser = class(....
private
  FPopupmenu: TPopupMenu;
protected
  ...
  procedure MouseUp(Sender: TObject; Key: Word); override;
  ...
published
  property PopupMenu: TPopupMenu read FPopupMenu write FPopupMenu;
end;

implementation

....

procedure TGeckoBrowser.MouseUp(Sender: TObject; Key: Word);
var
  x,y: integer;
begin
  inherited;
  if (key=VK_RBUTTON) and Assigned(PopupMenu) then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y;
    PopupMenu.Popup(x,y);
  end; {if}
end;  

或者,如果您不想在弹出菜单出现时触发 OnMouseUp,请执行以下操作:

implementation

....

procedure TGeckoBrowser.MouseUp(Sender: TObject; Key: Word);
var
  x,y: integer;
begin
  if (key=VK_RBUTTON) and Assigned(PopupMenu) then begin 
    x:= Mouse.CursorPos.X; 
    y:= Mouse.CursorPos.Y;
    PopupMenu.Popup(x,y);
  end {if}
  else inherited;
end;  

看到不同?Popupmenu 现在是您的组件的一部分(无论如何都是链接良好的部分),而不是碰巧在同一个表单上的东西。

于 2011-04-12T16:31:14.133 回答