ViewFilter.ShowContextMenu 方法 (Int32, Guid, IOleCommandTarget)

处理 SHOWCONTEXTMENU 命令显示上下文菜单。

命名空间:  Microsoft.VisualStudio.Package
程序集:  Microsoft.VisualStudio.Package.LanguageService(在 Microsoft.VisualStudio.Package.LanguageService.dll 中)

语法

声明
Public Overridable Sub ShowContextMenu ( _
    menuId As Integer, _
    groupGuid As Guid, _
    target As IOleCommandTarget _
)
public virtual void ShowContextMenu(
    int menuId,
    Guid groupGuid,
    IOleCommandTarget target
)

参数

  • groupGuid
    类型:System.Guid
    [in] 菜单 ID 执行菜单组的 GUID。

备注

调用此方法以处理在当前视图的上下文菜单。 这提供了一个机会显示拥有上下文菜单或修改现有菜单和显示它。

该基方法调用与 IDM_VS_CTXT_CODEWINmenuID , guidSHLMainMenugroupGuid 和在 ViewFilter 类实现的 IOleCommandTarget 接口的 target 。 该基方法确定宏是否不会记录然后不显示任何上下文菜单。

示例

这是基 ViewFilter 类如何实现此方法。

using System;
using Microsoft.VisualStudio.OLE.Interop;
using Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio.Package
{
    [CLSCompliant(false)]
    [System.Runtime.InteropServices.ComVisible(true)]
    public class ViewFilter :
        IVsTextViewFilter,
        IVsTextViewEvents,
        IOleCommandTarget,
        IDisposable
    {
        public virtual void ShowContextMenu(int menuId,
                                            Guid groupGuid,
                                            IOleCommandTarget target)
        {
            IVsUIShell uiShell = this.service.GetService(typeof(SVsUIShell)) as IVsUIShell;
            // disable context menu while recording macros.
            if (uiShell != null && !this.service.IsMacroRecordingOn())
            {
                System.Drawing.Point pt = System.Windows.Forms.Cursor.Position;
                POINTS[] pnts = new POINTS[1];
                pnts[0].x = (short)pt.X;
                pnts[0].y = (short)pt.Y;
                int hr = uiShell.ShowContextMenu(0, ref groupGuid, menuId, pnts, target);
                if (hr < 0)
                {
                    Debug.Assert(false, "uiShell.ShowContextMenu returned " + hr);
                }
            }
            uiShell = null;
        }
    }
}

.NET Framework 安全性

请参见

参考

ViewFilter 类

ShowContextMenu 重载

Microsoft.VisualStudio.Package 命名空间