windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-addservice-x28-system-dot-type-system-dot-object-x29.md
Adds the specified service to the service container.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.XtraRichEdit.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public void AddService(
Type serviceType,
object serviceInstance
)
Public Sub AddService(
serviceType As Type,
serviceInstance As Object
)
| Name | Type | Description |
|---|---|---|
| serviceType | Type |
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.
|
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.
var builtInService = richEditControl1.GetService<IRichEditCommandFactoryService>();
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl1,builtInService);
richEditControl1.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
Dim builtInService = richEditControl1.GetService(Of IRichEditCommandFactoryService)()
Dim myCommandFactory = New CustomRichEditCommandFactoryService(richEditControl1,builtInService)
richEditControl1.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)
The following code replaces the IRichEditCommandFactoryService service with its customized descendant.
var builtInService = richEditControl1.GetService<IRichEditCommandFactoryService>();
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl1,builtInService);
richEditControl1.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
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
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
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
richEditControl1.RemoveService(typeof(IRichEditCommandFactoryService));
richEditControl1.AddService(typeof(IRichEditCommandFactoryService), commandFactory);
}
rich-text-editor-document-content-validator/CS/ContentAnalyzer/Form1.cs#L18
richEditControl.AddService(typeof(ILogUnsupportedContentService), new LogUnsupportedContentService(this.log));
richEditControl.BeforeImport += OnBeforeImport;
how-to-use-docvariable-fields/VB/DocumentVariablesExample/Form1.vb#L46
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
richEditControl1.RemoveService(GetType(IRichEditCommandFactoryService))
richEditControl1.AddService(GetType(IRichEditCommandFactoryService), commandFactory)
richEditControl1.LoadDocument("testDocument.docx")
how-to-customize-copy-and-paste-commands/VB/Form1.vb#L26
richEditControl1.RemoveService(GetType(IRichEditCommandFactoryService))
richEditControl1.AddService(GetType(IRichEditCommandFactoryService), commandFactory)
End Sub
rich-text-editor-document-content-validator/VB/ContentAnalyzer/Form1.vb#L20
richEditControl.AddService(GetType(ILogUnsupportedContentService), New LogUnsupportedContentService(Me.log))
AddHandler richEditControl.BeforeImport, AddressOf OnBeforeImport
See Also
How to: Replace a Built-In Command with a Custom Command in Rich Text Editor for WinForms