windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-getservice-1.md
Gets the specified service.
Namespace : DevExpress.XtraRichEdit
Assembly : DevExpress.XtraRichEdit.v25.2.dll
NuGet Package : DevExpress.Win.RichEdit
public T GetService<T>()
where T : class
Public Function GetService(Of T As Class) As T
| Name | Description |
|---|---|
| T |
The service type.
|
| Type | Description |
|---|---|
| T |
A service object of the specified type or null for reference types and zero for numeric value types if a service is not available.
|
Use this method to enable your application objects to obtain a service of the RichEdit Control, in order to employ methods of the service. The control implements the IServiceProvider interface, so you can tell it what type of service you wish to retrieve; and if a service is available, it is offered to the caller object.
There is a set of predefined services you can retrieve. The IServiceProvider and IServiceContainer interface realization allows hiding implementation details, and provides more flexibility regarding future updates of the component.
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 GetService<T>() 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.
winforms-richedit-save-a-document/CS/SaveDocument/Form1.cs#L26
new CustomRichEditCommandFactoryService(richEditControl1,
richEditControl1.GetService<IRichEditCommandFactoryService>());
richEditControl1.ReplaceService<IRichEditCommandFactoryService>(commandFactory);
how-to-import-html-files-that-contain-images-referenced-with-custom-prefix/CS/Form1.cs#L21
// Custom IUriStreamProvider registration
IUriStreamService uriStreamService = richEditControl1.GetService<IUriStreamService>();
uriStreamService.RegisterProvider(new CustomUriStreamProvider(basePath, "bmp"));
winforms-richedit-use-images-in-mail-merge/CS/Form1.cs#L30
{
IUriStreamService uriStreamService = richEditControl.GetService<IUriStreamService>();
uriStreamService.RegisterProvider(new ImageStreamProvider(NorthwindDataProvider.Categories, "Picture"));
winforms-richedit-text-autocorrect-feature/CS/Expander/Form1.cs#L24
#region #autocorrectservice
IAutoCorrectService svc = richEditControl1.GetService<IAutoCorrectService>();
if (svc != null)
winforms-richedit-replace-standard-command-with-custom-command/CS/CustomCommand/Form1.cs#L29
public static void SetMyNewCommandFactory(RichEditControl control) {
var myCommandFactory = new CustomRichEditCommandFactoryService(control, control.GetService<IRichEditCommandFactoryService>());
control.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
winforms-richedit-save-a-document/VB/SaveDocument/Form1.vb#L20
InitializeComponent()
Dim commandFactory As CustomRichEditCommandFactoryService = New CustomRichEditCommandFactoryService(richEditControl1, richEditControl1.GetService(Of IRichEditCommandFactoryService)())
richEditControl1.ReplaceService(Of IRichEditCommandFactoryService)(commandFactory)
how-to-import-html-files-that-contain-images-referenced-with-custom-prefix/VB/Form1.vb#L20
' Custom IUriStreamProvider registration
Dim uriStreamService As IUriStreamService = richEditControl1.GetService(Of IUriStreamService)()
uriStreamService.RegisterProvider(New CustomUriStreamProvider(basePath, "bmp"))
winforms-richedit-use-images-in-mail-merge/VB/Form1.vb#L26
Private Sub RegisterUriStreamService(ByVal richEditControl As RichEditControl)
Dim uriStreamService As IUriStreamService = richEditControl.GetService(Of IUriStreamService)()
uriStreamService.RegisterProvider(New ImageStreamProvider(NorthwindDataProvider.Categories, "Picture"))
winforms-richedit-text-autocorrect-feature/VB/Expander/Form1.vb#L23
' #Region "#autocorrectservice"
Dim svc As IAutoCorrectService = richEditControl1.GetService(Of IAutoCorrectService)()
If svc IsNot Nothing Then
winforms-richedit-replace-standard-command-with-custom-command/VB/CustomCommand/Form1.vb#L33
Public Shared Sub SetMyNewCommandFactory(ByVal control As RichEditControl)
Dim myCommandFactory = New CustomRichEditCommandFactoryService(control, control.GetService(Of IRichEditCommandFactoryService)())
control.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)
See Also