Compartilhar via


BaseForm.ServiceProvider Propriedade

Definição

Obtém o objeto de serviço para a classe .

protected public:
 property IServiceProvider ^ ServiceProvider { IServiceProvider ^ get(); };
protected internal IServiceProvider ServiceProvider { get; }
member this.ServiceProvider : IServiceProvider
Protected Friend ReadOnly Property ServiceProvider As IServiceProvider

Valor da propriedade

A IServiceProvider interface para a classe .

Exemplos

O exemplo a seguir verifica se há alterações na lista de conexões e solicita que o usuário salve as alterações.

protected override void OnFormClosing(FormClosingEventArgs e) {

    base.OnFormClosing(e);

    CloseReason reason = e.CloseReason;
    if (reason != CloseReason.UserClosing &&
        reason != CloseReason.ApplicationExitCall)
        return;

    IServiceProvider serviceProvider = this.ServiceProvider;

    if (serviceProvider == null)
        return;

    IConnectionManager connectionManager = (IConnectionManager)
        GetService(typeof(IConnectionManager));

    if ((connectionManager == null) ||
        (!connectionManager.IsDirty))   // nothing to save
        return;

    DialogResult result = ShowMessage(
        "The connection list has changed. Save changes?",
        MessageBoxButtons.YesNoCancel,  // button set
        MessageBoxIcon.Question,         // Icon
        MessageBoxDefaultButton.Button1); // Default btn

    if (result == DialogResult.Yes) {
        connectionManager.Save();
    } else if (result == DialogResult.Cancel) {
        e.Cancel = true;
    }

} 

Aplica-se a