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;
}
}
Applies to
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for