Udostępnij za pośrednictwem


Interfejs TextDocumentKeyPressEvents

Definiuje zdarzenia skojarzone z naciśnięcie klawisza.Użycie tego obiektu dla funkcji i zapoznaj się z TextDocumentKeyPressEventsClass dla tego obiektu Członkowskiego dokumentacji.

Przestrzeń nazw:  EnvDTE80
Zestaw:  EnvDTE80 (w EnvDTE80.dll)

Składnia

'Deklaracja
<GuidAttribute("505B7600-8FCC-487C-9E4F-C7FD0B5FB690")> _
Public Interface TextDocumentKeyPressEvents _
    Inherits _TextDocumentKeyPressEvents, _dispTextDocumentKeyPressEvents_Event
[GuidAttribute("505B7600-8FCC-487C-9E4F-C7FD0B5FB690")]
public interface TextDocumentKeyPressEvents : _TextDocumentKeyPressEvents, 
    _dispTextDocumentKeyPressEvents_Event
[GuidAttribute(L"505B7600-8FCC-487C-9E4F-C7FD0B5FB690")]
public interface class TextDocumentKeyPressEvents : _TextDocumentKeyPressEvents, 
    _dispTextDocumentKeyPressEvents_Event
[<GuidAttribute("505B7600-8FCC-487C-9E4F-C7FD0B5FB690")>]
type TextDocumentKeyPressEvents =  
    interface 
        interface _TextDocumentKeyPressEvents 
        interface _dispTextDocumentKeyPressEvents_Event 
    end
public interface TextDocumentKeyPressEvents extends _TextDocumentKeyPressEvents, _dispTextDocumentKeyPressEvents_Event

Typ TextDocumentKeyPressEvents uwidacznia następujące elementy członkowskie.

Metody

  Nazwa Opis
Metoda publiczna add_AfterKeyPress Infrastruktura. Microsoft tylko do użytku wewnętrznego. (Odziedziczone z _dispTextDocumentKeyPressEvents_Event).
Metoda publiczna add_BeforeKeyPress Infrastruktura. Microsoft tylko do użytku wewnętrznego. (Odziedziczone z _dispTextDocumentKeyPressEvents_Event).
Metoda publiczna remove_AfterKeyPress Infrastruktura. Microsoft tylko do użytku wewnętrznego. (Odziedziczone z _dispTextDocumentKeyPressEvents_Event).
Metoda publiczna remove_BeforeKeyPress Infrastruktura. Microsoft tylko do użytku wewnętrznego. (Odziedziczone z _dispTextDocumentKeyPressEvents_Event).

Początek

Zdarzenia

  Nazwa Opis
Zdarzenie publiczne AfterKeyPress Infrastruktura. Microsoft tylko do użytku wewnętrznego. (Odziedziczone z _dispTextDocumentKeyPressEvents_Event).
Zdarzenie publiczne BeforeKeyPress Infrastruktura. Microsoft tylko do użytku wewnętrznego. (Odziedziczone z _dispTextDocumentKeyPressEvents_Event).

Początek

Przykłady

W tym przykładzie tworzy słownika małych ciąg i używa go do automatycznego tłumaczenia niektóre wyrazy angielskie z kolorów w celu ich szesnastkowe oświadczenia łącząc się z BeforeKeyPress zdarzenia.Zastąp kod w pliku Connect.cs z poniższego przykładowego kodu.Uruchom ten dodatek, a następnie otwórz dokument tekstowy w Visual Studio zintegrowane środowisko dewelopowania (IDE).W dokumencie tekst wpisz "red", "zielony" lub "niebieski" patrz metoda przechwytywania zdarzeń, odpowiednio tłumaczyć tekst "# ff0000", "# 00cc00" i "# 0000ff".Aby uzyskać więcej informacji na temat uruchamiania przykłady automatyzacji, zobacz Porady: kompilowanie i uruchamianie kodu modelu obiektów automatyzacji — przykłady.

namespace myAddin
{
  using System;
  using Microsoft.VisualStudio.CommandBars;
  using Extensibility;
  using EnvDTE;
  using EnvDTE80;
  using System.Windows.Forms;
  public class Connect : Object, IDTExtensibility2
  {
  public Connect()
  {
  }
  public void OnConnection(object application, 
ext_ConnectMode connectMode, object addInInst, ref Array custom)
  {
      _applicationObject = (DTE2)application;
      _addInInstance = (AddIn)addInInst;
      // Create a small string dictionary with keys and corresponding
      // values.
      myStringDictionary = new
 System.Collections.Specialized.StringDictionary();
      myStringDictionary.Add("red", "#ff0000");
      myStringDictionary.Add("green", "#00cc00");
      myStringDictionary.Add("blue", "#0000ff");
      EnvDTE80.Events2 events =
 (EnvDTE80.Events2)_applicationObject.Events;
      textDocKeyEvents =
 (EnvDTE80.TextDocumentKeyPressEvents)
events.get_TextDocumentKeyPressEvents(null);
      // Connect to the BeforeKeyPress delegate exposed from the
      // TextDocumentKeyPressEvents object retrieved above.
      textDocKeyEvents.BeforeKeyPress +=new
 _dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler
(BeforeKeyPress);
  }
  public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
  {
      if (textDocKeyEvents != null)
      {
          textDocKeyEvents.BeforeKeyPress -= new 
_dispTextDocumentKeyPressEvents_BeforeKeyPressEventHandler
(BeforeKeyPress);
      }
  }
  public void OnAddInsUpdate(ref Array custom)
  {
  }
  public void OnStartupComplete(ref Array custom)
  {
  }
  public void OnBeginShutdown(ref Array custom)
  {
  }
  void BeforeKeyPress(string Keypress, EnvDTE.TextSelection Selection,
 bool InStatementCompletion, ref bool CancelKeypress)
  {
  if ((Keypress == " ") || (Keypress == "\t"))
      {
          EditPoint ep = Selection.ActivePoint.CreateEditPoint();
          EditPoint sp = ep.CreateEditPoint();
          sp.CharLeft(1);
          while (true)
          {
              string txt = sp.GetText(ep);
              if (myStringDictionary.ContainsKey(txt))
              {
                  sp.Delete(txt.Length);
                  sp.Insert(myStringDictionary[txt]);
                  CancelKeypress = true;
                  return;
              }
          sp.CharLeft(1);
          if ((ep.Line != sp.Line) || ((ep.DisplayColumn == 1) 
&& (ep.Line == 1)))
              break;
          }
       }
  }
  private DTE2 _applicationObject;
  private AddIn _addInInstance;
  private EnvDTE80.TextDocumentKeyPressEvents textDocKeyEvents;
  System.Collections.Specialized.StringDictionary myStringDictionary;
  }
}

Zobacz też

Informacje

Przestrzeń nazw EnvDTE80