Back to Devexpress

RichEditControl.AddService(Type, Object) Method

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-addservice-x28-system-dot-type-system-dot-object-x29.md

latest8.4 KB
Original Source

RichEditControl.AddService(Type, Object) Method

Adds the specified service to the service container.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
public void AddService(
    Type serviceType,
    object serviceInstance
)
vb
Public Sub AddService(
    serviceType As Type,
    serviceInstance As Object
)

Parameters

NameTypeDescription
serviceTypeType

The type of service to add.

| | serviceInstance | Object |

An instance of the service type to add. This object must implement or inherit from the type indicated by the serviceType parameter.

|

Remarks

The RichEditControl implements IServiceProvider and IServiceContainer interfaces. In addition to providing services, it also provides a mechanism for adding and removing services. To obtain a service, call the RichEditControl.GetService method.

The following code replaces the IRichEditCommandFactoryService service with its customized descendant.

View Example

csharp
var builtInService = richEditControl1.GetService<IRichEditCommandFactoryService>();
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl1,builtInService);
richEditControl1.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
vb
Dim builtInService = richEditControl1.GetService(Of IRichEditCommandFactoryService)()
Dim myCommandFactory = New CustomRichEditCommandFactoryService(richEditControl1,builtInService)
richEditControl1.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)

Example

The following code replaces the IRichEditCommandFactoryService service with its customized descendant.

View Example

csharp
var builtInService = richEditControl1.GetService<IRichEditCommandFactoryService>();
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl1,builtInService);
richEditControl1.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
vb
Dim builtInService = richEditControl1.GetService(Of IRichEditCommandFactoryService)()
Dim myCommandFactory = New CustomRichEditCommandFactoryService(richEditControl1,builtInService)
richEditControl1.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)

The following code snippets (auto-collected from DevExpress Examples) contain references to the AddService(Type, Object) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

how-to-use-docvariable-fields/CS/DocumentVariablesExample/Form1.cs#L45

csharp
richEditControl1.RemoveService(typeof(IProgressIndicationService));
richEditControl1.AddService(typeof(IProgressIndicationService),
    new MyProgressIndicatorService(richEditControl1, this.progressBarControl1));

winforms-richedit-copy-a-table-to-the-clipboard-in-the-unicode-text-format/CS/Form1.cs#L17

csharp
richEditControl1.RemoveService(typeof(IRichEditCommandFactoryService));
richEditControl1.AddService(typeof(IRichEditCommandFactoryService), commandFactory);
richEditControl1.LoadDocument("testDocument.docx");

how-to-customize-copy-and-paste-commands/CS/RichEditCustomCopyPaste/Form1.cs#L16

csharp
richEditControl1.RemoveService(typeof(IRichEditCommandFactoryService));
    richEditControl1.AddService(typeof(IRichEditCommandFactoryService), commandFactory);
}

rich-text-editor-document-content-validator/CS/ContentAnalyzer/Form1.cs#L18

csharp
richEditControl.AddService(typeof(ILogUnsupportedContentService), new LogUnsupportedContentService(this.log));
richEditControl.BeforeImport += OnBeforeImport;

how-to-use-docvariable-fields/VB/DocumentVariablesExample/Form1.vb#L46

vb
richEditControl1.RemoveService(GetType(IProgressIndicationService))
    richEditControl1.AddService(GetType(IProgressIndicationService), New MyProgressIndicatorService(richEditControl1, progressBarControl1))
End Sub

winforms-richedit-copy-a-table-to-the-clipboard-in-the-unicode-text-format/VB/Form1.vb#L18

vb
richEditControl1.RemoveService(GetType(IRichEditCommandFactoryService))
richEditControl1.AddService(GetType(IRichEditCommandFactoryService), commandFactory)
richEditControl1.LoadDocument("testDocument.docx")

how-to-customize-copy-and-paste-commands/VB/Form1.vb#L26

vb
richEditControl1.RemoveService(GetType(IRichEditCommandFactoryService))
    richEditControl1.AddService(GetType(IRichEditCommandFactoryService), commandFactory)
End Sub

rich-text-editor-document-content-validator/VB/ContentAnalyzer/Form1.vb#L20

vb
richEditControl.AddService(GetType(ILogUnsupportedContentService), New LogUnsupportedContentService(Me.log))
AddHandler richEditControl.BeforeImport, AddressOf OnBeforeImport

See Also

GetService(Type)

RichEditControl Services

ReplaceService<T>(T)

How to: Replace a Built-In Command with a Custom Command in Rich Text Editor for WinForms

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace