Udostępnij za pośrednictwem


Metoda ViewFilter.ShowContextMenu — (Int32, Guid, IOleCommandTarget)

Obsługuje SHOWCONTEXTMENU polecenia, aby wyświetlić menu kontekstowe.

Przestrzeń nazw:  Microsoft.VisualStudio.Package
Zestaw:  Microsoft.VisualStudio.Package.LanguageService (w Microsoft.VisualStudio.Package.LanguageService.dll)

Składnia

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

Parametry

  • menuId
    Typ: System.Int32
    [w] Identyfikator menu, aby pokazać.
  • groupGuid
    Typ: System.Guid
    [w] Identyfikator GUID grupy menu, z którego pochodzi identyfikator menu.

Uwagi

Metoda ta jest wywoływana do obsługi menu kontekstowego w bieżącym widoku.Zapewnia to możliwość wyświetlania z menu kontekstowego lub zmodyfikować istniejące menu i pokazać je.

Metody podstawowej jest wywoływana z menuID z IDM_VS_CTXT_CODEWIN, groupGuid z guidSHLMainMenui target z IOleCommandTarget interfejs implementowany na ViewFilter klasy.Metody podstawowej Określa, czy makra nie są rejestrowane, a następnie pokazuje menu kontekstowego.

Przykłady

Oto jak podstawy ViewFilter klasy implementuje tej metody.

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;
        }
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ViewFilter Klasa

Przeciążenie ShowContextMenu

Przestrzeń nazw Microsoft.VisualStudio.Package