IWindowsFormsEditorService Interface
Assembly: System.Windows.Forms (in system.windows.forms.dll)
The IWindowsFormsEditorService is only available through the GetService method of the PropertyGrid control.
This service is typically used to display a form from the EditValue method of a UITypeEditor. When a PropertyGrid invokes the EditValue method of a UITypeEditor to provide a user interface for editing the value of a property, the EditValue method is passed a reference to an IServiceProvider that can typically provide an instance of the IWindowsFormsEditorService. The methods of this service can be used to display dialog boxes and forms, or to show a Control within a drop down container that is shown on top of the property grid near the area of the value field whose value is being edited.
The following example provides an example UITypeEditor that uses an IWindowsFormsEditorService to display a Form for user input.
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Drawing Imports System.Drawing.Design Imports System.Windows.Forms Imports System.Windows.Forms.Design ' Example UITypeEditor that uses the IWindowsFormsEditorService ' to display a Form. <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> Public Class TestDialogEditor Inherits System.Drawing.Design.UITypeEditor Public Sub New() End Sub Public Overloads Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle ' Indicates that this editor can display a Form-based interface. Return UITypeEditorEditStyle.Modal End Function Public Overloads Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object ' Attempts to obtain an IWindowsFormsEditorService. Dim edSvc As IWindowsFormsEditorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService) If edSvc Is Nothing Then Return Nothing End If ' Displays a StringInputDialog Form to get a user-adjustable ' string value. Dim form As New StringInputDialog(CStr(value)) If edSvc.ShowDialog(form) = DialogResult.OK Then Return form.inputTextBox.Text End If ' If OK was not pressed, return the original value Return value End Function End Class ' Example Form for entering a string. Friend Class StringInputDialog Inherits System.Windows.Forms.Form Private ok_button As System.Windows.Forms.Button Private cancel_button As System.Windows.Forms.Button Public inputTextBox As System.Windows.Forms.TextBox Public Sub New(ByVal [text] As String) InitializeComponent() inputTextBox.Text = [text] End Sub Private Sub InitializeComponent() Me.ok_button = New System.Windows.Forms.Button() Me.cancel_button = New System.Windows.Forms.Button() Me.inputTextBox = New System.Windows.Forms.TextBox() Me.SuspendLayout() Me.ok_button.Anchor = System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right Me.ok_button.Location = New System.Drawing.Point(180, 43) Me.ok_button.Name = "ok_button" Me.ok_button.TabIndex = 1 Me.ok_button.Text = "OK" Me.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK Me.cancel_button.Anchor = System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right Me.cancel_button.Location = New System.Drawing.Point(260, 43) Me.cancel_button.Name = "cancel_button" Me.cancel_button.TabIndex = 2 Me.cancel_button.Text = "Cancel" Me.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.inputTextBox.Location = New System.Drawing.Point(6, 9) Me.inputTextBox.Name = "inputTextBox" Me.inputTextBox.Size = New System.Drawing.Size(327, 20) Me.inputTextBox.TabIndex = 0 Me.inputTextBox.Text = "" Me.inputTextBox.Anchor = System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right Me.ClientSize = New System.Drawing.Size(342, 73) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.inputTextBox, Me.cancel_button, Me.ok_button}) Me.MinimumSize = New System.Drawing.Size(350, 100) Me.Name = "StringInputDialog" Me.Text = "String Input Dialog" Me.ResumeLayout(False) End Sub End Class ' Provides an example control that displays instructions in design mode, ' with which the example UITypeEditor is associated. Public Class WinFormsEdServiceDialogExampleControl Inherits UserControl <EditorAttribute(GetType(TestDialogEditor), GetType(UITypeEditor))> _ Public Property TestDialogString() As String Get Return localDialogTestString End Get Set(ByVal Value As String) localDialogTestString = Value End Set End Property Private localDialogTestString As String Public Sub New() localDialogTestString = "Test String" Me.Size = New Size(210, 74) Me.BackColor = Color.Beige End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) If Me.DesignMode Then e.Graphics.DrawString("Use the Properties window to show", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 5) e.Graphics.DrawString("a Form dialog box, using the", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 17) e.Graphics.DrawString("IWindowsFormsEditorService, for", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 29) e.Graphics.DrawString("configuring this control's", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 41) e.Graphics.DrawString("TestDialogString property.", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 53) Else e.Graphics.DrawString("This example requires design mode.", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 5) End If End Sub End Class
package IWindowsFormsEditorServiceExample;
import System.*;
import System.ComponentModel.*;
import System.ComponentModel.Design.*;
import System.Drawing.*;
import System.Drawing.Design.*;
import System.Windows.Forms.*;
import System.Windows.Forms.Design.*;
// Example UITypeEditor that uses the IWindowsFormsEditorService
// to display a Form.
/** @attribute System.Security.Permissions.PermissionSet(System.Security.
Permissions.SecurityAction.Demand, Name = "FullTrust")
*/
public class TestDialogEditor extends System.Drawing.Design.UITypeEditor
{
public TestDialogEditor()
{
} //TestDialogEditor
public System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.
ComponentModel.ITypeDescriptorContext context)
{
// Indicates that this editor can display a Form-based interface.
return UITypeEditorEditStyle.Modal;
} //GetEditStyle
public Object EditValue(System.ComponentModel.
ITypeDescriptorContext context, System.IServiceProvider provider,
Object value)
{
// Attempts to obtain an IWindowsFormsEditorService.
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.
GetService(IWindowsFormsEditorService.class.ToType());
if (edSvc.Equals(null)) {
return null;
}
// Displays a StringInputDialog Form to get a user-adjustable
// string value.
StringInputDialog form = new StringInputDialog((String)value);
if ((edSvc.ShowDialog(form)).Equals(DialogResult.OK)) {
return form.inputTextBox.get_Text();
}
// If OK was not pressed, return the original value
return value;
} //EditValue
} //TestDialogEditor
// Example Form for entering a string.
class StringInputDialog extends System.Windows.Forms.Form
{
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton;
public System.Windows.Forms.TextBox inputTextBox;
public StringInputDialog(String text)
{
InitializeComponent();
inputTextBox.set_Text(text);
} //StringInputDialog
private void InitializeComponent()
{
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.inputTextBox = new System.Windows.Forms.TextBox();
this.SuspendLayout();
this.okButton.set_Anchor(System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right);
this.okButton.set_Location(new System.Drawing.Point(180, 43));
this.okButton.set_Name("ok_Button");
this.okButton.set_TabIndex(1);
this.okButton.set_Text("OK");
this.okButton.set_DialogResult(System.Windows.Forms.DialogResult.OK);
this.cancelButton.set_Anchor(System.Windows.Forms.AnchorStyles.Bottom
| System.Windows.Forms.AnchorStyles.Right);
this.cancelButton.set_Location(new System.Drawing.Point(260, 43));
this.cancelButton.set_Name("cancel_Button");
this.cancelButton.set_TabIndex(2);
this.cancelButton.set_Text("Cancel");
this.cancelButton.set_DialogResult(System.Windows.Forms.DialogResult.
Cancel);
this.inputTextBox.set_Location(new System.Drawing.Point(6, 9));
this.inputTextBox.set_Name("inputTextBox");
this.inputTextBox.set_Size(new System.Drawing.Size(327, 20));
this.inputTextBox.set_TabIndex(0);
this.inputTextBox.set_Text("");
this.inputTextBox.set_Anchor(System.Windows.Forms.AnchorStyles.Top |
System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.
AnchorStyles.Right);
this.set_ClientSize(new System.Drawing.Size(342, 73));
this.get_Controls().AddRange(new System.Windows.Forms.Control[] { this.
inputTextBox, this.cancelButton, this.okButton });
this.set_MinimumSize(new System.Drawing.Size(350, 100));
this.set_Name("StringInputDialog");
this.set_Text("String Input Dialog");
this.ResumeLayout(false);
} //InitializeComponent
} //StringInputDialog
// Provides an example control that displays instructions in design mode,
// with which the example UITypeEditor is associated.
public class WinFormsEdServiceDialogExampleControl extends UserControl
{
/** @attribute EditorAttribute(TestDialogEditor.class, UITypeEditor.class)
*/
/** @property
*/
public String get_TestDialogString()
{
return localDialogTestString;
} //get_TestDialogString
/** @property
*/
public void set_TestDialogString(String value)
{
localDialogTestString = value;
} //set_TestDialogString
private String localDialogTestString;
public WinFormsEdServiceDialogExampleControl()
{
localDialogTestString = "Test String";
this.set_Size(new Size(210, 74));
this.set_BackColor(Color.get_Beige());
} //WinFormsEdServiceDialogExampleControl
protected void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
if (this.get_DesignMode()) {
e.get_Graphics().DrawString("Use the Properties window to show",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 5, 5);
e.get_Graphics().DrawString("a Form dialog box, using the",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 5, 17);
e.get_Graphics().DrawString("IWindowsFormsEditorService, for",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 5, 29);
e.get_Graphics().DrawString("configuring this control's",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 5, 41);
e.get_Graphics().DrawString("TestDialogString property.",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 5, 53);
}
else {
e.get_Graphics().DrawString("This example requires design mode.",
new Font("Arial", 8), new SolidBrush(Color.get_Black()), 5, 5);
}
} //OnPaint
} //WinFormsEdServiceDialogExampleControl
The following example provides an example UITypeEditor that uses an IWindowsFormsEditorService to display a drop-down UserControl for user input.
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Drawing Imports System.Drawing.Design Imports System.Windows.Forms Imports System.Windows.Forms.Design ' Example UITypeEditor that uses the IWindowsFormsEditorService to ' display a drop-down control. <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Public Class TestDropDownEditor Inherits System.Drawing.Design.UITypeEditor Public Sub New() End Sub Public Overloads Overrides Function GetEditStyle(ByVal context As System.ComponentModel.ITypeDescriptorContext) As System.Drawing.Design.UITypeEditorEditStyle ' Indicates that this editor can display a control-based ' drop-down interface. Return UITypeEditorEditStyle.DropDown End Function Public Overloads Overrides Function EditValue(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal provider As System.IServiceProvider, ByVal value As Object) As Object ' Attempts to obtain an IWindowsFormsEditorService. Dim edSvc As IWindowsFormsEditorService = CType(provider.GetService(GetType(IWindowsFormsEditorService)), IWindowsFormsEditorService) If edSvc Is Nothing Then Return value End If ' Displays a drop-down control. Dim inputControl As New StringInputControl(CStr(value), edSvc) edSvc.DropDownControl(inputControl) Return inputControl.inputTextBox.Text End Function End Class ' Example control for entering a string. Friend Class StringInputControl Inherits System.Windows.Forms.UserControl Public inputTextBox As System.Windows.Forms.TextBox Private WithEvents ok_button As System.Windows.Forms.Button Private WithEvents cancel_button As System.Windows.Forms.Button Private edSvc As IWindowsFormsEditorService Public Sub New(ByVal [text] As String, ByVal edSvc As IWindowsFormsEditorService) InitializeComponent() inputTextBox.Text = [text] ' Stores IWindowsFormsEditorService reference to use to ' close the control. Me.edSvc = edSvc End Sub Private Sub InitializeComponent() Me.inputTextBox = New System.Windows.Forms.TextBox() Me.ok_button = New System.Windows.Forms.Button() Me.cancel_button = New System.Windows.Forms.Button() Me.SuspendLayout() Me.inputTextBox.Anchor = System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Left Or System.Windows.Forms.AnchorStyles.Right Me.inputTextBox.Location = New System.Drawing.Point(6, 7) Me.inputTextBox.Name = "inputTextBox" Me.inputTextBox.Size = New System.Drawing.Size(336, 20) Me.inputTextBox.TabIndex = 0 Me.inputTextBox.Text = "" Me.ok_button.Anchor = System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right Me.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK Me.ok_button.Location = New System.Drawing.Point(186, 38) Me.ok_button.Name = "ok_button" Me.ok_button.TabIndex = 1 Me.ok_button.Text = "OK" Me.cancel_button.Anchor = System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right Me.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel Me.cancel_button.Location = New System.Drawing.Point(267, 38) Me.cancel_button.Name = "cancel_button" Me.cancel_button.TabIndex = 2 Me.cancel_button.Text = "Cancel" Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.cancel_button, Me.ok_button, Me.inputTextBox}) Me.Name = "StringInputControl" Me.Size = New System.Drawing.Size(350, 70) Me.ResumeLayout(False) End Sub Private Sub CloseControl(ByVal sender As Object, ByVal e As EventArgs) Handles ok_button.Click, cancel_button.Click edSvc.CloseDropDown() End Sub End Class ' Provides an example control that displays instructions in design mode, ' with which the example UITypeEditor is associated. Public Class WinFormsEdServiceDropDownExampleControl Inherits UserControl <EditorAttribute(GetType(TestDropDownEditor), GetType(UITypeEditor))> _ Public Property TestDropDownString() As String Get Return localDropDownTestString End Get Set(ByVal Value As String) localDropDownTestString = Value End Set End Property Private localDropDownTestString As String Public Sub New() localDropDownTestString = "Test String" Me.Size = New Size(210, 74) Me.BackColor = Color.Beige End Sub Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) If Me.DesignMode Then e.Graphics.DrawString("Use the Properties window to show", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 5) e.Graphics.DrawString("a drop-down control, using the", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 17) e.Graphics.DrawString("IWindowsFormsEditorService, for", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 29) e.Graphics.DrawString("configuring this control's", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 41) e.Graphics.DrawString("TestDropDownString property.", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 53) Else e.Graphics.DrawString("This example requires design mode.", New Font("Arial", 8), New SolidBrush(Color.Black), 5, 5) End If End Sub End Class
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.