我有一个与TTabControl
关联的弹出菜单。我希望能够选择选项卡并单击右键单击下拉菜单。我似乎还记得其他控件会有一个右键选择属性。
答案 0 :(得分:2)
您可以使用OnPopup
的{{1}}事件处理程序:
TPopupMenu
答案 1 :(得分:0)
您可以执行以下操作:
type
TTabControl = class(Vcl.ComCtrls.TTabControl)
private
FRightClickSelect: Boolean;
procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
public
constructor Create(AOwner: TComponent); override;
published
property RightClickSelect: Boolean read FRightClickSelect write FRightClickSelect default False;
end;
implementation
uses
Winapi.CommCtrl;
{ TTabControl }
constructor TTabControl.Create(AOwner: TComponent);
begin
inherited;
FRightClickSelect := False;
end;
procedure TTabControl.CNNotify(var Msg: TWMNotify);
var
Index: Integer;
HitInfo: TTCHitTestInfo;
begin
if FRightClickSelect and (Msg.NMHdr.code = NM_RCLICK) then
begin
HitInfo.pt := ScreenToClient(Mouse.CursorPos);
Index := SendMessage(Handle, TCM_HITTEST, 0, LPARAM(@HitInfo));
if (Index <> -1) and (HitInfo.flags <> TCHT_NOWHERE) then
TabIndex := Index;
end;
inherited;
end;