次の方法で共有


IWindowsFormsEditorService インターフェイス

UITypeEditors にインターフェイスを提供して、Windows フォームを表示したり、デザイン モードでプロパティ グリッド コントロールからドロップダウン領域のコントロールを表示します。

この型のすべてのメンバの一覧については、IWindowsFormsEditorService メンバ を参照してください。

Public Interface IWindowsFormsEditorService
[C#]
public interface IWindowsFormsEditorService
[C++]
public __gc __interface IWindowsFormsEditorService
[JScript]
public interface IWindowsFormsEditorService

解説

IWindowsFormsEditorService は、 PropertyGrid コントロールの GetService メソッドを通じてだけ使用できます。

このサービスは、通常、 UITypeEditorEditValue メソッドからフォームを表示するために使用されます。 PropertyGridUITypeEditorEditValue メソッドを呼び出して、プロパティの値を編集するためのユーザー インターフェイスを提供する場合、 EditValue メソッドには、通常 IWindowsFormsEditorService のインスタンスを提供する IServiceProvider への参照が渡されます。このサービスのメソッドを使用することによって、ダイアログ ボックスやフォームを表示したり、ドロップダウン コンテナ内の Control を表示できます。このコンテナは、編集中の値を持つ値フィールド領域に近いプロパティ グリッドの上に表示されます。

使用例

[Visual Basic, C#, C++] IWindowsFormsEditorService を使用してユーザー入力用の Form を表示する UITypeEditor の例を次に示します。

 
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.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        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

[C#] 
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace IWindowsFormsEditorServiceExample
{    
    // Example UITypeEditor that uses the IWindowsFormsEditorService 
    // to display a Form.
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
    public class TestDialogEditor : System.Drawing.Design.UITypeEditor
    {
        public TestDialogEditor()
        {
        }

        public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            // Indicates that this editor can display a Form-based interface.
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            // Attempts to obtain an IWindowsFormsEditorService.
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if( edSvc == null )
                return null;         
            
            // Displays a StringInputDialog Form to get a user-adjustable 
            // string value.
            StringInputDialog form = new StringInputDialog((string)value);
            if( edSvc.ShowDialog(form) == DialogResult.OK )
                return form.inputTextBox.Text;

            // If OK was not pressed, return the original value
            return value;
        }        
    }

    // Example Form for entering a string.
    internal class StringInputDialog : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button ok_button;
        private System.Windows.Forms.Button cancel_button;
        public System.Windows.Forms.TextBox inputTextBox;

        public StringInputDialog(string text)
        {
            InitializeComponent();
            inputTextBox.Text = text;
        }

        private void InitializeComponent()
        {
            this.ok_button = new System.Windows.Forms.Button();
            this.cancel_button = new System.Windows.Forms.Button();
            this.inputTextBox = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            this.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.ok_button.Location = new System.Drawing.Point(180, 43);
            this.ok_button.Name = "ok_button";
            this.ok_button.TabIndex = 1;
            this.ok_button.Text = "OK";      
            this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;            
            this.cancel_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.cancel_button.Location = new System.Drawing.Point(260, 43);
            this.cancel_button.Name = "cancel_button";
            this.cancel_button.TabIndex = 2;
            this.cancel_button.Text = "Cancel";            
            this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.inputTextBox.Location = new System.Drawing.Point(6, 9);
            this.inputTextBox.Name = "inputTextBox";
            this.inputTextBox.Size = new System.Drawing.Size(327, 20);
            this.inputTextBox.TabIndex = 0;
            this.inputTextBox.Text = "";            
            this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(342, 73);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.inputTextBox,
                                                                          this.cancel_button,
                                                                          this.ok_button});
            this.MinimumSize = new System.Drawing.Size(350, 100);
            this.Name = "StringInputDialog";
            this.Text = "String Input Dialog";
            this.ResumeLayout(false);
        }        
    }

    // Provides an example control that displays instructions in design mode,
    // with which the example UITypeEditor is associated.
    public class WinFormsEdServiceDialogExampleControl : UserControl
    {
        [EditorAttribute(typeof(TestDialogEditor), typeof(UITypeEditor))]
        public string TestDialogString
        {
            get
            {
                return localDialogTestString;
            }
            set
            {
                localDialogTestString = value;
            }
        }
        private string localDialogTestString;
      
        public WinFormsEdServiceDialogExampleControl()
        {
            localDialogTestString = "Test String"; 
            this.Size = new Size(210, 74);
            this.BackColor = Color.Beige;
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if( this.DesignMode )
            {
                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);
            }
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Drawing::Design;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

namespace IWindowsFormsEditorServiceExample {

   // Example Form for entering a string.
private __gc class StringInputDialog : public System::Windows::Forms::Form {
private:
   System::Windows::Forms::Button*  ok_button;
   System::Windows::Forms::Button*  cancel_button;

public:
   System::Windows::Forms::TextBox*  inputTextBox;

   StringInputDialog(String* text) {
      InitializeComponent();
      inputTextBox->Text = text;
   }

private:
   void InitializeComponent() {
      this->ok_button = new System::Windows::Forms::Button();
      this->cancel_button = new System::Windows::Forms::Button();
      this->inputTextBox = new System::Windows::Forms::TextBox();
      this->SuspendLayout();
      this->ok_button->Anchor = static_cast<AnchorStyles>(System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right);
      this->ok_button->Location =  System::Drawing::Point(180, 43);
      this->ok_button->Name = S"ok_button";
      this->ok_button->TabIndex = 1;
      this->ok_button->Text = S"OK";
      this->ok_button->DialogResult = System::Windows::Forms::DialogResult::OK;
      this->cancel_button->Anchor = static_cast<AnchorStyles>(System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Right);
      this->cancel_button->Location =  System::Drawing::Point(260, 43);
      this->cancel_button->Name = S"cancel_button";
      this->cancel_button->TabIndex = 2;
      this->cancel_button->Text = S"Cancel";
      this->cancel_button->DialogResult = System::Windows::Forms::DialogResult::Cancel;
      this->inputTextBox->Location =  System::Drawing::Point(6, 9);
      this->inputTextBox->Name = S"inputTextBox";
      this->inputTextBox->Size =  System::Drawing::Size(327, 20);
      this->inputTextBox->TabIndex = 0;
      this->inputTextBox->Text = S"";
      this->inputTextBox->Anchor = static_cast<AnchorStyles>(System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Left
         | System::Windows::Forms::AnchorStyles::Right);
      this->AutoScaleBaseSize =  System::Drawing::Size(5, 13);
      this->ClientSize =  System::Drawing::Size(342, 73);

      System::Windows::Forms::Control* temp0 [] = {this->inputTextBox, this->cancel_button, this->ok_button};
      this->Controls->AddRange(temp0);
      this->MinimumSize =  System::Drawing::Size(350, 100);
      this->Name = S"StringInputDialog";
      this->Text = S"String Input Dialog";
      this->ResumeLayout(false);
   }
};

// Example UITypeEditor that uses the IWindowsFormsEditorService
// to display a Form.
public __gc class TestDialogEditor : public System::Drawing::Design::UITypeEditor {
public:
   TestDialogEditor() {
   }
   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")] 
   System::Drawing::Design::UITypeEditorEditStyle GetEditStyle(System::ComponentModel::ITypeDescriptorContext* context) {
      // Indicates that this editor can display a Form-based interface.
      return UITypeEditorEditStyle::Modal;
   }

   [System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")] 
   Object* EditValue(System::ComponentModel::ITypeDescriptorContext* context, System::IServiceProvider* provider, Object* value) {
      // Attempts to obtain an IWindowsFormsEditorService.
      IWindowsFormsEditorService* edSvc = dynamic_cast<IWindowsFormsEditorService*>(provider->GetService(__typeof(IWindowsFormsEditorService)));
      if (edSvc == 0)
         return 0;

      // Displays a StringInputDialog Form to get a user-adjustable
      // string value.
      StringInputDialog* form = new StringInputDialog(dynamic_cast<String*>(value));
      if (edSvc->ShowDialog(form) == DialogResult::OK)
         return form->inputTextBox->Text;

      // If OK was not pressed, return the original value
      return value;
   }
};

// Provides an example control that displays instructions in design mode,
// with which the example UITypeEditor is associated.
public __gc class WinFormsEdServiceDialogExampleControl : public UserControl {
public:
   [EditorAttribute(__typeof(TestDialogEditor), __typeof(UITypeEditor))]
   __property String* get_TestDialogString() {
      return localDialogTestString;
   }
   __property void set_TestDialogString(String* value) {
      localDialogTestString = value;
   }

private:
   String*  localDialogTestString;

public:
   WinFormsEdServiceDialogExampleControl() {
      localDialogTestString = S"Test String";
      this->Size =  System::Drawing::Size(210, 74);
      this->BackColor = Color::Beige;
   }

protected:
   void OnPaint(System::Windows::Forms::PaintEventArgs* e) {
      if (this->DesignMode) {
         e->Graphics->DrawString(S"Use the Properties window to show", new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 5);
         e->Graphics->DrawString(S"a Form dialog box, using the", new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 17);
         e->Graphics->DrawString(S"IWindowsFormsEditorService, for", new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 29);
         e->Graphics->DrawString(S"configuring this control's", new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 41);
         e->Graphics->DrawString(S"TestDialogString property.", new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 53);
      } else {
         e->Graphics->DrawString(S"This example requires design mode.", new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 5);
      }
   }
};
}

[Visual Basic, C#, C++] IWindowsFormsEditorService を使用してユーザー入力用のドロップダウン UserControl を表示する UITypeEditor の例を次に示します。

 
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.
Public Class TestDropDownEditor
   Inherits System.Drawing.Design.UITypeEditor
   
   Public Sub New()
    End Sub
    
   <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    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

    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    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

[C#] 
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace IWindowsFormsEditorServiceExample
{    
    // Example UITypeEditor that uses the IWindowsFormsEditorService to 
    // display a drop-down control.
    public class TestDropDownEditor : System.Drawing.Design.UITypeEditor
    {
        public TestDropDownEditor()
        {
        }

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
        public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
        {
            // Indicates that this editor can display a control-based 
            // drop-down interface.
            return UITypeEditorEditStyle.DropDown;
        }

    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")]
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            // Attempts to obtain an IWindowsFormsEditorService.
            IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if( edSvc == null )
                return value;       
            
            // Displays a drop-down control.
            StringInputControl inputControl = new StringInputControl((string)value, edSvc);
            edSvc.DropDownControl(inputControl);
            return inputControl.inputTextBox.Text;
        }
    }

    // Example control for entering a string.
    internal class StringInputControl : System.Windows.Forms.UserControl
    {
        public System.Windows.Forms.TextBox inputTextBox;
        private System.Windows.Forms.Button ok_button;
        private System.Windows.Forms.Button cancel_button;
        private IWindowsFormsEditorService edSvc;

        public StringInputControl(string text, IWindowsFormsEditorService edSvc)
        {
            InitializeComponent();
            inputTextBox.Text = text;
            // Stores IWindowsFormsEditorService reference to use to 
            // close the control.
            this.edSvc = edSvc;
        }

        private void InitializeComponent()
        {
            this.inputTextBox = new System.Windows.Forms.TextBox();
            this.ok_button = new System.Windows.Forms.Button();
            this.cancel_button = new System.Windows.Forms.Button();
            this.SuspendLayout();
            this.inputTextBox.Anchor = ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.inputTextBox.Location = new System.Drawing.Point(6, 7);
            this.inputTextBox.Name = "inputTextBox";
            this.inputTextBox.Size = new System.Drawing.Size(336, 20);
            this.inputTextBox.TabIndex = 0;
            this.inputTextBox.Text = "";
            this.ok_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.ok_button.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.ok_button.Location = new System.Drawing.Point(186, 38);
            this.ok_button.Name = "ok_button";
            this.ok_button.TabIndex = 1;
            this.ok_button.Text = "OK";
            this.ok_button.Click += new EventHandler(this.CloseControl);
            this.cancel_button.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
            this.cancel_button.DialogResult = System.Windows.Forms.DialogResult.Cancel;            
            this.cancel_button.Location = new System.Drawing.Point(267, 38);
            this.cancel_button.Name = "cancel_button";
            this.cancel_button.TabIndex = 2;
            this.cancel_button.Text = "Cancel";
            this.cancel_button.Click += new EventHandler(this.CloseControl);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.cancel_button,
                                                                          this.ok_button,
                                                                          this.inputTextBox});
            this.Name = "StringInputControl";
            this.Size = new System.Drawing.Size(350, 70);
            this.ResumeLayout(false);
        }

        private void CloseControl(object sender, EventArgs e)
        {
            edSvc.CloseDropDown();
        }
    }
    
    // Provides an example control that displays instructions in design mode,
    // with which the example UITypeEditor is associated.
    public class WinFormsEdServiceDropDownExampleControl : UserControl
    {
        [EditorAttribute(typeof(TestDropDownEditor), typeof(UITypeEditor))]
        public string TestDropDownString
        {
            get
            {
                return localDropDownTestString;
            }
            set
            {       
                localDropDownTestString = value;
            }
        }
        
        private string localDropDownTestString;

        public WinFormsEdServiceDropDownExampleControl()
        {
            localDropDownTestString = "Test String";
            this.Size = new Size(210, 74);
            this.BackColor = Color.Beige;
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if( this.DesignMode )
            {
                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);
            }
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>

using namespace System;
using namespace System::ComponentModel;
using namespace System::ComponentModel::Design;
using namespace System::Drawing;
using namespace System::Drawing::Design;
using namespace System::Windows::Forms;
using namespace System::Windows::Forms::Design;

namespace IWindowsFormsEditorServiceExample {
   // Example control for entering a string.
private __gc class StringInputControl : public System::Windows::Forms::UserControl {
public:
   System::Windows::Forms::TextBox*  inputTextBox;
private:
   System::Windows::Forms::Button*  ok_button;
   System::Windows::Forms::Button*  cancel_button;
   IWindowsFormsEditorService*  edSvc;

public:
   StringInputControl(String* text, IWindowsFormsEditorService* edSvc) {
      InitializeComponent();
      inputTextBox->Text = text;
      // Stores IWindowsFormsEditorService reference to use to
      // close the control.
      this->edSvc = edSvc;
   }

private:
   void InitializeComponent() {
      this->inputTextBox = new System::Windows::Forms::TextBox();
      this->ok_button = new System::Windows::Forms::Button();
      this->cancel_button = new System::Windows::Forms::Button();
      this->SuspendLayout();
      this->inputTextBox->Anchor = static_cast<AnchorStyles>(
         System::Windows::Forms::AnchorStyles::Top
         | System::Windows::Forms::AnchorStyles::Left
         | System::Windows::Forms::AnchorStyles::Right);
      this->inputTextBox->Location =  System::Drawing::Point(6, 7);
      this->inputTextBox->Name = S"inputTextBox";
      this->inputTextBox->Size =  System::Drawing::Size(336, 20);
      this->inputTextBox->TabIndex = 0;
      this->inputTextBox->Text = S"";
      this->ok_button->Anchor = static_cast<AnchorStyles>(
         System::Windows::Forms::AnchorStyles::Bottom
         | System::Windows::Forms::AnchorStyles::Right);
      this->ok_button->DialogResult = System::Windows::Forms::DialogResult::OK;
      this->ok_button->Location =  System::Drawing::Point(186, 38);
      this->ok_button->Name = S"ok_button";
      this->ok_button->TabIndex = 1;
      this->ok_button->Text = S"OK";
      this->ok_button->Click += new EventHandler(this, &StringInputControl::CloseControl);
      this->cancel_button->Anchor = static_cast<AnchorStyles>(
         System::Windows::Forms::AnchorStyles::Bottom
         | System::Windows::Forms::AnchorStyles::Right);
      this->cancel_button->DialogResult = System::Windows::Forms::DialogResult::Cancel;
      this->cancel_button->Location =  System::Drawing::Point(267, 38);
      this->cancel_button->Name = S"cancel_button";
      this->cancel_button->TabIndex = 2;
      this->cancel_button->Text = S"Cancel";
      this->cancel_button->Click += new EventHandler(this, &StringInputControl::CloseControl);

      System::Windows::Forms::Control* temp0 [] = {this->cancel_button,
         this->ok_button,
         this->inputTextBox};

      this->Controls->AddRange(temp0);
      this->Name = S"StringInputControl";
      this->Size =  System::Drawing::Size(350, 70);
      this->ResumeLayout(false);
   }

   void CloseControl(Object* /*sender*/, EventArgs* /*e*/) {
      edSvc->CloseDropDown();
   }
};

// Example UITypeEditor that uses the IWindowsFormsEditorService to
// display a drop-down control.
public __gc class TestDropDownEditor : public System::Drawing::Design::UITypeEditor {
public:
   TestDropDownEditor() {
   }
[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
   System::Drawing::Design::UITypeEditorEditStyle GetEditStyle(
      System::ComponentModel::ITypeDescriptorContext* /*context*/) {
      // Indicates that this editor can display a control-based
      // drop-down interface.
      return UITypeEditorEditStyle::DropDown;
   }
[System::Security::Permissions::PermissionSet(System::Security::Permissions::SecurityAction::Demand, Name="FullTrust")]
   Object* EditValue(
      System::ComponentModel::ITypeDescriptorContext* /*context*/,
      System::IServiceProvider* provider,
      Object* value) {
      // Attempts to obtain an IWindowsFormsEditorService.
      IWindowsFormsEditorService* edSvc = dynamic_cast<IWindowsFormsEditorService*>(
         provider->GetService(__typeof(IWindowsFormsEditorService)));
      if (edSvc == 0)
         return value;

      // Displays a drop-down control.
      StringInputControl* inputControl = new StringInputControl(
         dynamic_cast<String*>(value), edSvc);
      edSvc->DropDownControl(inputControl);
      return inputControl->inputTextBox->Text;
   }
};

// Provides an example control that displays instructions in design mode,
// with which the example UITypeEditor is associated.
public __gc class WinFormsEdServiceDropDownExampleControl : public UserControl {
public:
   [EditorAttribute(__typeof(TestDropDownEditor), __typeof(UITypeEditor))]
   __property String* get_TestDropDownString() {
      return localDropDownTestString;
   }
   __property void set_TestDropDownString(String* value) {
      localDropDownTestString = value;
   }

private:
   String*  localDropDownTestString;

public:
   WinFormsEdServiceDropDownExampleControl() {
      localDropDownTestString = S"Test String";
      this->Size =  System::Drawing::Size(210, 74);
      this->BackColor = Color::Beige;
   }

protected:
   void OnPaint(System::Windows::Forms::PaintEventArgs* e) {
      if (this->DesignMode) {
         e->Graphics->DrawString(S"Use the Properties window to show",
            new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 5);
         e->Graphics->DrawString(S"a drop-down control, using the",
            new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 17);
         e->Graphics->DrawString(S"IWindowsFormsEditorService, for",
            new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 29);
         e->Graphics->DrawString(S"configuring this control's",
            new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 41);
         e->Graphics->DrawString(S"TestDropDownString property.",
            new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 53);
      } else {
         e->Graphics->DrawString(S"This example requires design mode.",
            new System::Drawing::Font(S"Arial", 8), new SolidBrush(Color::Black), 5, 5);
      }
   }
};
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

名前空間: System.Windows.Forms.Design

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

アセンブリ: System.Windows.Forms (System.Windows.Forms.dll 内)

参照

IWindowsFormsEditorService メンバ | System.Windows.Forms.Design 名前空間