BaseForm.GetService(Type) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Retrieves the requested service.
protected public:
System::Object ^ GetService(Type ^ serviceType);
protected internal object GetService (Type serviceType);
override this.GetService : Type -> obj
Protected Friend Function GetService (serviceType As Type) As Object
Parameters
- serviceType
- Type
The service object.
Returns
The requested service.
Examples
The following example uses the service object from the GetService method to add two services.
class MyShellFrm : BaseForm, IFrameHost {
public MyShellFrm(IServiceProvider serviceProvider,
ShellComponents shellComponents)
: base(serviceProvider) {
_uiService = new UI_Svc((IWin32Window)this, (IFrameHost)this);
_downLoadSvc = new DownLoadSvc();
_propEditSvc = new PropEditSvc();
_shellComponents = shellComponents;
SuspendLayout();
try {
if (_uiService.RightToLeftLayout) {
RightToLeft = RightToLeft.Yes;
RightToLeftLayout = true;
}
IServiceContainer serviceContainer = (IServiceContainer)
GetService(typeof(IServiceContainer));
Debug.Assert(serviceContainer != null);
if (serviceContainer != null) {
serviceContainer.AddService(
typeof(IManagementUIService), _uiService);
serviceContainer.AddService(
typeof(IPropertyEditingService), _propEditSvc);
}
setWidthHeightBounds();
Font = (Font)((IManagementUIService)_uiService).Styles["DialogFont"];
Text = "My custom tool";
Icon = getMyIcon();
_managementFrame = new ManagementFrame(serviceProvider, this);
_managementFrame.SuspendLayout();
try {
_managementFrame.Name = "_managementFrame";
_managementFrame.Dock = DockStyle.Fill;
Controls.Add(_managementFrame);
} finally {
_managementFrame.ResumeLayout(false);
}
} finally {
ResumeLayout();
}
}