BaseForm.GetService(Type) Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Recupera o serviço solicitado.
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
Parâmetros
- serviceType
- Type
O objeto de serviço.
Retornos
O serviço solicitado.
Exemplos
O exemplo a seguir usa o objeto de serviço do GetService método para adicionar dois serviços.
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();
}
}