Freigeben über


ComponentDesigner.GetService-Methode

Versucht, den angegebenen Diensttyp von der Entwurfsmodussite der Komponente des Designers abzurufen.

Namespace: System.ComponentModel.Design
Assembly: System.Design (in system.design.dll)

Syntax

'Declaration
Protected Overridable Function GetService ( _
    serviceType As Type _
) As Object
'Usage
Dim serviceType As Type
Dim returnValue As Object

returnValue = Me.GetService(serviceType)
protected virtual Object GetService (
    Type serviceType
)
protected:
virtual Object^ GetService (
    Type^ serviceType
)
protected Object GetService (
    Type serviceType
)
protected function GetService (
    serviceType : Type
) : Object

Parameter

  • serviceType
    Der Typ des anzufordernden Dienstes.

Rückgabewert

Eine Objektimplementierung des angeforderten Dienstes oder NULL (Nothing in Visual Basic), wenn der Dienst nicht ermittelt werden kann.

Hinweise

In der Standardimplementierung dieser Methode wird der Dienst von der Site der Komponente angefordert.

Beispiel

Im folgenden Codebeispiel wird die Verwendung der GetService-Methode für den Zugriff auf Designerdienste veranschaulicht.

' This utility method connects the designer to various
' services it will use. 
Private Sub InitializeServices()

    ' Acquire a reference to DesignerActionService.
    Me.actionService = GetService(GetType(DesignerActionService))

    ' Acquire a reference to DesignerActionUIService.
    Me.actionUiService = GetService(GetType(DesignerActionUIService))

    ' Acquire a reference to IComponentChangeService.
    Me.changeService = GetService(GetType(IComponentChangeService))

    ' Hook the IComponentChangeService events.
    If Not (Me.changeService Is Nothing) Then
        AddHandler Me.changeService.ComponentChanged, AddressOf ChangeService_ComponentChanged

        AddHandler Me.changeService.ComponentAdded, AddressOf ChangeService_ComponentAdded

        AddHandler Me.changeService.ComponentRemoved, AddressOf changeService_ComponentRemoved
    End If

    ' Acquire a reference to ISelectionService.
    Me.selectionService = GetService(GetType(ISelectionService))

    ' Hook the SelectionChanged event.
    If Not (Me.selectionService Is Nothing) Then
        AddHandler Me.selectionService.SelectionChanged, AddressOf selectionService_SelectionChanged
    End If

    ' Acquire a reference to IDesignerEventService.
    Me.eventService = GetService(GetType(IDesignerEventService))

    If Not (Me.eventService Is Nothing) Then
        AddHandler Me.eventService.ActiveDesignerChanged, AddressOf eventService_ActiveDesignerChanged
    End If

    ' Acquire a reference to IDesignerHost.
    Me.host = GetService(GetType(IDesignerHost))

    ' Acquire a reference to IDesignerOptionService.
    Me.optionService = GetService(GetType(IDesignerOptionService))

    ' Acquire a reference to IEventBindingService.
    Me.eventBindingService = GetService(GetType(IEventBindingService))

    ' Acquire a reference to IExtenderListService.
    Me.listService = GetService(GetType(IExtenderListService))

    ' Acquire a reference to IReferenceService.
    Me.referenceService = GetService(GetType(IReferenceService))

    ' Acquire a reference to ITypeResolutionService.
    Me.typeResService = GetService(GetType(ITypeResolutionService))

    ' Acquire a reference to IComponentDiscoveryService.
    Me.componentDiscoveryService = GetService(GetType(IComponentDiscoveryService))

    ' Acquire a reference to IToolboxService.
    Me.toolboxService = GetService(GetType(IToolboxService))

    ' Acquire a reference to UndoEngine.
    Me.undoEng = GetService(GetType(UndoEngine))

    If Not (Me.undoEng Is Nothing) Then
        MessageBox.Show("UndoEngine")
    End If
End Sub
// This utility method connects the designer to various
// services it will use. 
private void InitializeServices()
{
    // Acquire a reference to DesignerActionService.
    this.actionService =
        GetService(typeof(DesignerActionService))
        as DesignerActionService;

    // Acquire a reference to DesignerActionUIService.
    this.actionUiService =
        GetService(typeof(DesignerActionUIService))
        as DesignerActionUIService;

    // Acquire a reference to IComponentChangeService.
    this.changeService =
        GetService(typeof(IComponentChangeService))
        as IComponentChangeService;

    // Hook the IComponentChangeService events.
    if (this.changeService != null)
    {
        this.changeService.ComponentChanged +=
            new ComponentChangedEventHandler(
            ChangeService_ComponentChanged);

        this.changeService.ComponentAdded +=
            new ComponentEventHandler(
            ChangeService_ComponentAdded);

        this.changeService.ComponentRemoved +=
            new ComponentEventHandler(
            changeService_ComponentRemoved);
    }

    // Acquire a reference to ISelectionService.
    this.selectionService =
        GetService(typeof(ISelectionService))
        as ISelectionService;

    // Hook the SelectionChanged event.
    if (this.selectionService != null)
    {
        this.selectionService.SelectionChanged +=
            new EventHandler(selectionService_SelectionChanged);
    }

    // Acquire a reference to IDesignerEventService.
    this.eventService =
        GetService(typeof(IDesignerEventService))
        as IDesignerEventService;

    if (this.eventService != null)
    {
        this.eventService.ActiveDesignerChanged +=
            new ActiveDesignerEventHandler(
            eventService_ActiveDesignerChanged);
    }

    // Acquire a reference to IDesignerHost.
    this.host =
        GetService(typeof(IDesignerHost))
        as IDesignerHost;

    // Acquire a reference to IDesignerOptionService.
    this.optionService =
        GetService(typeof(IDesignerOptionService))
        as IDesignerOptionService;

    // Acquire a reference to IEventBindingService.
    this.eventBindingService =
        GetService(typeof(IEventBindingService))
        as IEventBindingService;

    // Acquire a reference to IExtenderListService.
    this.listService =
        GetService(typeof(IExtenderListService))
        as IExtenderListService;

    // Acquire a reference to IReferenceService.
    this.referenceService =
        GetService(typeof(IReferenceService))
        as IReferenceService;

    // Acquire a reference to ITypeResolutionService.
    this.typeResService =
        GetService(typeof(ITypeResolutionService))
        as ITypeResolutionService;

    // Acquire a reference to IComponentDiscoveryService.
    this.componentDiscoveryService =
        GetService(typeof(IComponentDiscoveryService))
        as IComponentDiscoveryService;

    // Acquire a reference to IToolboxService.
    this.toolboxService =
        GetService(typeof(IToolboxService))
        as IToolboxService;

    // Acquire a reference to UndoEngine.
    this.undoEng =
        GetService(typeof(UndoEngine))
        as UndoEngine;

    if (this.undoEng != null)
    {
        MessageBox.Show("UndoEngine");
    }
}

.NET Framework-Sicherheit

  • Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter .

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ComponentDesigner-Klasse
ComponentDesigner-Member
System.ComponentModel.Design-Namespace

Weitere Ressourcen

Gewusst wie: Zugriff auf Entwurfszeitdienste