BaseForm.ServiceProvider Property
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.
Gets the service object for the class.
protected public:
property IServiceProvider ^ ServiceProvider { IServiceProvider ^ get(); };
protected internal IServiceProvider ServiceProvider { get; }
member this.ServiceProvider : IServiceProvider
Protected Friend ReadOnly Property ServiceProvider As IServiceProvider
Property Value
The IServiceProvider interface for the class.
Examples
The following example checks for changes in the connection list and prompts the user to save any changes.
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;
}
}