RichEditControl.AddService(Type, Object) Method
Adds the specified service to the service container.
Namespace: DevExpress.XtraRichEdit
Assembly: DevExpress.XtraRichEdit.v20.2.dll
Declaration
public void AddService(
Type serviceType,
object serviceInstance
)
Public Sub AddService(
serviceType As Type,
serviceInstance As Object
)
Parameters
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. |
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.
NOTE
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-the-richeditcontrols-common-api-t210437
richEditControl.Text = "A message box is displayed after saving a document using the 'Save' or 'Save As' button click since custom commands.";
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl, richEditControl.GetService<IRichEditCommandFactoryService>());
richEditControl.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);
Examples
The following code replaces the IRichEditCommandFactoryService service with its customized descendant.
NOTE
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-the-richeditcontrols-common-api-t210437
richEditControl.Text = "A message box is displayed after saving a document using the 'Save' or 'Save As' button click since custom commands.";
var myCommandFactory = new CustomRichEditCommandFactoryService(richEditControl, richEditControl.GetService<IRichEditCommandFactoryService>());
richEditControl.ReplaceService<IRichEditCommandFactoryService>(myCommandFactory);