开发者

Delphi: PopUpMenu

There is a list View + a PopUpMenu. I need that the PopUpMenu appears when items are present. The menu must not appears when 0 items.

Is this approximate code appropriate (can be used as a basis)?

procedure TForm1.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y:开发者_如何学C Integer);
var P: TPoint;
begin
  P:=GetClientOrigin;
  if Button = mbRight then
     PopupMenu1.Popup(X+P.X+StringGrid1.Left, Y+P.Y+StringGrid1.Top);
end;

Are there other ways?

Thanks!!!


Firstly, don't do anything on a mouse event because the popup menu can be invoked from the keyboard.

The best way to do this, in my view, is to handle the OnPopup event. If you want the menu not to appear call Abort.

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  if SomeCondition then
    Abort;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜