Export (0) Print
Expand All

ComponentDesigner.GetService Method

Attempts to retrieve the specified type of service from the design mode site of the designer's component.

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

protected virtual Object GetService(
	Type serviceType
)

Parameters

serviceType
Type: System.Type

The type of service to request.

Return Value

Type: System.Object
An object implementing the requested service, or null if the service cannot be resolved.

The default implementation of this method requests the service from the site of the component.

The following code example demonstrates the use of the GetService method to access designer services.

    // 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

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft