Back to Devexpress

RichEditControl.GetService<T>() Method

windowsforms-devexpress-dot-xtrarichedit-dot-richeditcontrol-dot-getservice-1.md

latest8.2 KB
Original Source

RichEditControl.GetService<T>() Method

Gets the specified service.

Namespace : DevExpress.XtraRichEdit

Assembly : DevExpress.XtraRichEdit.v25.2.dll

NuGet Package : DevExpress.Win.RichEdit

Declaration

csharp
public T GetService<T>()
    where T : class
vb
Public Function GetService(Of T As Class) As T

Type Parameters

NameDescription
T

The service type.

|

Returns

TypeDescription
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.

|

Remarks

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.

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

csharp
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

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

csharp
{
    IUriStreamService uriStreamService = richEditControl.GetService<IUriStreamService>();
    uriStreamService.RegisterProvider(new ImageStreamProvider(NorthwindDataProvider.Categories, "Picture"));

winforms-richedit-text-autocorrect-feature/CS/Expander/Form1.cs#L24

csharp
#region #autocorrectservice
IAutoCorrectService svc = richEditControl1.GetService<IAutoCorrectService>();
if (svc != null)

winforms-richedit-replace-standard-command-with-custom-command/CS/CustomCommand/Form1.cs#L29

csharp
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

vb
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

vb
' 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

vb
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

vb
' #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

vb
Public Shared Sub SetMyNewCommandFactory(ByVal control As RichEditControl)
    Dim myCommandFactory = New CustomRichEditCommandFactoryService(control, control.GetService(Of IRichEditCommandFactoryService)())
    control.ReplaceService(Of IRichEditCommandFactoryService)(myCommandFactory)

See Also

DevExpress.XtraRichEdit.Services

RichEditControl Class

RichEditControl Members

DevExpress.XtraRichEdit Namespace