ControlDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


ControlDesigner クラスは、Visual Studio 2005 などのデザイン ホストで、デザイン時に Web サーバー コントロールをサポートするために継承および拡張できる基本コントロール デザイナ クラスを提供します。
デザイン時の表示を処理するオブジェクト モデルは、以前のバージョンに比べて強化されており、簡略化されたオブジェクト モデルにアクセスできるようにするために、次の新しい基本クラスが追加されています。
オートフォーマットさまざまなオートフォーマットおよび定義済み書式を作成して、ページ開発者が複雑なスタイル変更をカスタムの Web サーバー コントロールに適用する場合の処理を簡単にできます。たとえば、ControlDesigner クラスから派生した TableDesigner コントロールには、選択できる多数のオートフォーマットが用意されています。カスタム コントロールでオートフォーマットを実装および提供するには、次の機能を使用します。
アクション リストは、コントロールを使用するページ開発者が Visual Studio 2005 などのデザイン時ユーザー インターフェイス (UI: User Interface) で実行できる、重要なタスクまたは一般的に使用されるタスクのメニューです。たとえば、コントロールのデザイン時ビューに、利用できるタスクのメニューを用意できます。これには、コントロールの書式を自動設定するタスクも含まれます。アクション リストの機能を習得するには、まず次の機能を使用してみてください。
領域は、Web サーバー コントロールのデザイン時ビューの編集可能な領域です。この機能により、デザイン時に、テンプレート コンテンツ、内部コントロール、およびプロパティを WYSIWYG 形式で編集できます。コントロール デザイナによって領域内にコントロールが作成されるようにすることも、ツールボックスを使用してコントロールを領域内にドラッグ アンド ドロップすることもできます。領域は、次の機能で管理します。
GridView コントロールなどのテンプレート コントロールをデザイン時に編集するための UI の作成モデルは、以前のバージョンに比べて大幅に強化されています。コントロールのさまざまなパーツのテンプレートを含む複雑なカスタム コントロールを作成できます。また、カスタム コントロールのデザイナにより、次の機能を使用して、テンプレートを変更するページ開発者を支援できます。

ControlDesigner クラスから派生した単純なデザイナ クラスを作成する方法のコード例を次に示します。このコントロール デザイナは、カスタム TextControl クラスをサポートし、デザイン時にコントロールのテキスト サイズを変更するコマンドを提供します。コントロール デザイナは、TextControl クラスの DesignerAttribute オブジェクト宣言でコントロール デザイナを指定することにより、コントロールと関連付けられます。コントロール デザイナから HTML マークアップへのプロパティの変更を永続化するためのキーは、カスタム ActionList クラスの ToggleTextSize メソッドにあります。
この例を実行するには、System.Design.dll アセンブリへの参照を追加し、コードをコンパイルします。
Imports Microsoft.VisualBasic Imports System.Web.UI Imports System.Web.UI.Design Imports System.Web.UI.WebControls Imports System.ComponentModel Imports System.ComponentModel.Design Namespace ASPNet.Design.Samples.VB ' Simple text Web control renders a text string. ' This control is associated with the TextSizeWebControlDesigner. <DesignerAttribute(GetType(TextSizeWebControlDesigner)), _ ToolboxData("<{0}:TextControl runat='server'></{0}:TextControl>")> _ Public Class TextControl Inherits Label Private _largeText As Boolean = True ' Constructor Public Sub New() Text = "Test Phrase" SetSize() End Sub ' Determines whether the text is large or small <Bindable(True), Category("Appearance"), DefaultValue(True)> _ Public Property LargeText() As Boolean Get Return _largeText End Get Set(ByVal value As Boolean) _largeText = value SetSize() End Set End Property ' Applies the LargeText property to the control Private Sub SetSize() If LargeText Then Me.Font.Size = FontUnit.XLarge Else Me.Font.Size = FontUnit.Small End If End Sub End Class ' This control designer offers DesignerActionList commands ' that can alter the design time html of the associated control. Public Class TextSizeWebControlDesigner Inherits ControlDesigner Private _actionLists As DesignerActionListCollection ' Do not allow direct resizing of the control Public Overrides ReadOnly Property AllowResize() As Boolean Get Return False End Get End Property ' Return a custom ActionList collection Public Overrides ReadOnly Property ActionLists() As System.ComponentModel.Design.DesignerActionListCollection Get If IsNothing(_actionLists) Then _actionLists = New DesignerActionListCollection() _actionLists.AddRange(MyBase.ActionLists) ' Add a custom DesignerActionList _actionLists.Add(New ActionList(Me)) End If Return _actionLists End Get End Property ' Create a custom class of DesignerActionList Public Class ActionList Inherits DesignerActionList Private _parent As TextSizeWebControlDesigner Private _items As DesignerActionItemCollection ' Constructor Public Sub New(ByRef parent As TextSizeWebControlDesigner) MyBase.New(parent.Component) _parent = parent End Sub ' Create the ActionItem collection and add one command Public Overrides Function GetSortedActionItems() As DesignerActionItemCollection If IsNothing(_items) Then _items = New DesignerActionItemCollection() _items.Add(New DesignerActionMethodItem(Me, "ToggleLargeText", "Toggle Text Size", True)) End If Return _items End Function ' ActionList command to change the text size Private Sub ToggleLargeText() ' Get a reference to the parent designer's associated control Dim ctl As TextControl = CType(_parent.Component, TextControl) ' Get a reference to the control's LargeText property Dim propDesc As PropertyDescriptor = TypeDescriptor.GetProperties(ctl)("LargeText") ' Get the current value of the property Dim v As Boolean = CType(propDesc.GetValue(ctl), Boolean) ' Toggle the property value propDesc.SetValue(ctl, (Not v)) End Sub End Class End Class End Namespace <br /><span space="preserve">...</span><br /><%@ Page Language="VB" %> <%@ Register TagPrefix="aspSample" Namespace="ASPNet.Design.Samples.VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <aspSample:TextControl ID=TextControl1 runat="server"> </aspSample:TextControl> </div> </form> </body> </html>
using System; using System.Web.UI; using System.Drawing; using System.Web.UI.Design; using System.Web.UI.WebControls; using System.ComponentModel; using System.ComponentModel.Design; namespace ASPNet.Design.Samples.CS { // Simple text Web control renders a text string. // This control is associated with the TextSizeWebControlDesigner. [DesignerAttribute(typeof(TextSizeWebControlDesigner)), ToolboxData("<{0}:TextControl runat=\"server\"></{0}:TextControl>")] public class TextControl : Label { private bool _largeText = true; // Constructor public TextControl() { Text = "Test Phrase"; SetSize(); } // Determines whether the text is large or small [Bindable(true), Category("Appearance"), DefaultValue("true")] public bool LargeText { get { return _largeText; } set { _largeText = value; SetSize(); } } // Applies the LargeText property to the control private void SetSize() { if (LargeText) this.Font.Size = FontUnit.XLarge; else this.Font.Size = FontUnit.Small; } } // This control designer offers DesignerActionList commands // that can alter the design time html of the associated control. public class TextSizeWebControlDesigner : ControlDesigner { private DesignerActionListCollection _actionLists = null; // Do not allow direct resizing of the control public override bool AllowResize { get { return false; } } // Return a custom ActionList collection public override DesignerActionListCollection ActionLists { get { if (_actionLists == null) { _actionLists = new DesignerActionListCollection(); _actionLists.AddRange(base.ActionLists); // Add a custom DesignerActionList _actionLists.Add(new ActionList(this)); } return _actionLists; } } public class ActionList : DesignerActionList { private TextSizeWebControlDesigner _parent; private DesignerActionItemCollection _items; // Constructor public ActionList(TextSizeWebControlDesigner parent) : base(parent.Component) { _parent = parent; } // Create the ActionItem collection and add one command public override DesignerActionItemCollection GetSortedActionItems() { if (_items == null) { _items = new DesignerActionItemCollection(); _items.Add(new DesignerActionMethodItem(this, "ToggleLargeText", "Toggle Text Size", true)); } return _items; } // ActionList command to change the text size private void ToggleLargeText() { // Get a reference to the parent designer's associated control TextControl ctl = (TextControl)_parent.Component; // Get a reference to the control's LargeText property PropertyDescriptor propDesc = TypeDescriptor.GetProperties(ctl)["LargeText"]; // Get the current value of the property bool v = (bool)propDesc.GetValue(ctl); // Toggle the property value propDesc.SetValue(ctl, !v); } } } } <br /><span space="preserve">...</span><br /><%@ Page Language="C#" %> <%@ Register TagPrefix="aspSample" Namespace="ASPNet.Design.Samples.CS" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> </script> <html > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <aspSample:TextControl ID=TextControl1 runat="server"> </aspSample:TextControl> </div> </form> </body> </html>


System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
派生クラス


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


ControlDesigner クラス
アセンブリ: System.Design (system.design.dll 内)


ControlDesigner は、Control から派生するコンポーネントのデザイナで使用する基本クラスを提供します。ControlDesigner は、ComponentDesigner クラスから継承したメソッドと機能の他に、デザイン時に関連する Control の動作を拡張および変更するための追加のメソッドを提供します。
DesignerAttribute を使用してデザイナに型を関連付けることができます。デザイン時の動作のカスタマイズの概要については、「デザイン時サポートの拡張」を参照してください。

MouseEnter イベントおよび MouseLeave イベントを処理し、デザイナ コードからコントロール上に描画し、IDesignerFilter インターフェイスの一部を使用してデザイン時にコントロールのプロパティを追加する、ControlDesigner 実装の例を次に示します。このサンプル コードには、デザイナおよびそのデザイナに関連付けられたサンプル ユーザー コントロールが含まれます。このサンプルをビルドするには、サンプルをコンパイルしてクラス ライブラリを作成し、このライブラリへの参照を Windows フォーム プロジェクトに追加します。次に、このコントロールをツールボックスに追加し、コントロールのインスタンスをフォームに追加します。このコントロールをポイントすると、コントロールを囲んでいる内側のアウトラインが強調表示されます。アウトラインには、デザイナがコントロールのプロパティのリストに追加した OutlineColor プロパティに対応した色が使用されます。
Imports System Imports System.ComponentModel Imports System.ComponentModel.Design Imports System.Collections Imports System.Drawing Imports System.Windows.Forms Imports System.Windows.Forms.Design Namespace ControlDesignerExample _ ' ExampleControlDesigner is an example control designer that ' demonstrates basic functions of a ControlDesigner. <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Public Class TestControlDesigner Inherits System.Windows.Forms.Design.ControlDesigner ' This boolean state reflects whether the mouse is over the control. Private mouseover As Boolean = False ' This color is a private field for the OutlineColor property. Private lineColor As Color = Color.White ' This color is used to outline the control when the mouse is ' over the control. Public Property OutlineColor() As Color Get Return lineColor End Get Set(ByVal Value As Color) lineColor = Value End Set End Property Public Sub New() End Sub ' Sets a value and refreshes the control's display when the ' mouse position enters the area of the control. Protected Overrides Sub OnMouseEnter() Me.mouseover = True Me.Control.Refresh() End Sub ' Sets a value and refreshes the control's display when the ' mouse position enters the area of the control. Protected Overrides Sub OnMouseLeave() Me.mouseover = False Me.Control.Refresh() End Sub ' Draws an outline around the control when the mouse is ' over the control. Protected Overrides Sub OnPaintAdornments(ByVal pe As System.Windows.Forms.PaintEventArgs) If Me.mouseover Then pe.Graphics.DrawRectangle(New Pen(New SolidBrush(Me.lineColor), 6), 0, 0, Me.Control.Size.Width, Me.Control.Size.Height) End If End Sub ' Adds a property to this designer's control at design time ' that indicates the outline color to use. Protected Overrides Sub PreFilterProperties(ByVal properties As System.Collections.IDictionary) properties.Add("OutlineColor", TypeDescriptor.CreateProperty(GetType(TestControlDesigner), "OutlineColor", GetType(System.Drawing.Color), Nothing)) End Sub End Class ' This example control demonstrates the ExampleControlDesigner. <DesignerAttribute(GetType(TestControlDesigner))> _ Public Class TestControl Inherits System.Windows.Forms.UserControl Private components As System.ComponentModel.Container = Nothing Public Sub New() components = New System.ComponentModel.Container() End Sub Protected Overloads Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub End Class End Namespace
using System; using System.ComponentModel; using System.ComponentModel.Design; using System.Collections; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.Design; namespace ControlDesignerExample { // ExampleControlDesigner is an example control designer that // demonstrates basic functions of a ControlDesigner. [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] public class ExampleControlDesigner : System.Windows.Forms.Design.ControlDesigner { // This boolean state reflects whether the mouse is over the control. private bool mouseover = false; // This color is a private field for the OutlineColor property. private Color lineColor = Color.White; // This color is used to outline the control when the mouse is // over the control. public Color OutlineColor { get { return lineColor; } set { lineColor = value; } } public ExampleControlDesigner() { } // Sets a value and refreshes the control's display when the // mouse position enters the area of the control. protected override void OnMouseEnter() { this.mouseover = true; this.Control.Refresh(); } // Sets a value and refreshes the control's display when the // mouse position enters the area of the control. protected override void OnMouseLeave() { this.mouseover = false; this.Control.Refresh(); } // Draws an outline around the control when the mouse is // over the control. protected override void OnPaintAdornments(System.Windows.Forms.PaintEventArgs pe) { if(this.mouseover) pe.Graphics.DrawRectangle(new Pen(new SolidBrush(this.lineColor), 6), 0, 0, this.Control.Size.Width, this.Control.Size.Height); } // Adds a property to this designer's control at design time // that indicates the outline color to use. protected override void PreFilterProperties(System.Collections.IDictionary properties) { properties.Add("OutlineColor", TypeDescriptor.CreateProperty(typeof(ExampleControlDesigner), "OutlineColor", typeof(System.Drawing.Color), null)); } } // This example control demonstrates the ExampleControlDesigner. [DesignerAttribute(typeof(ExampleControlDesigner))] public class ExampleControl : System.Windows.Forms.UserControl { private System.ComponentModel.Container components = null; public ExampleControl() { components = new System.ComponentModel.Container(); } protected override void Dispose( bool disposing ) { if( disposing ) { if( components != null ) components.Dispose(); } base.Dispose( disposing ); } } }
using namespace System; using namespace System::ComponentModel; using namespace System::ComponentModel::Design; using namespace System::Collections; using namespace System::Drawing; using namespace System::Windows::Forms; using namespace System::Windows::Forms::Design; using namespace System::Security::Permissions; public ref class TestControlDesigner: public System::Windows::Forms::Design::ControlDesigner { private: bool mouseover; Color lineColor; public: property Color OutlineColor { Color get() { return lineColor; } void set( Color value ) { lineColor = value; } } TestControlDesigner() { mouseover = false; lineColor = Color::White; } protected: virtual void OnMouseEnter() override { this->mouseover = true; this->Control->Refresh(); } virtual void OnMouseLeave() override { this->mouseover = false; this->Control->Refresh(); } virtual void OnPaintAdornments( System::Windows::Forms::PaintEventArgs^ pe ) override { if ( this->mouseover ) pe->Graphics->DrawRectangle( gcnew Pen( gcnew SolidBrush( this->lineColor ),6 ), 0, 0, this->Control->Size.Width, this->Control->Size.Height ); } protected: [ReflectionPermission(SecurityAction::Demand, Flags=ReflectionPermissionFlag::MemberAccess)] virtual void PreFilterProperties( System::Collections::IDictionary^ properties ) override { properties->Add( "OutlineColor", TypeDescriptor::CreateProperty( TestControlDesigner::typeid, "OutlineColor", System::Drawing::Color::typeid, nullptr ) ); } }; [DesignerAttribute(TestControlDesigner::typeid)] public ref class TestControl: public System::Windows::Forms::UserControl { private: System::ComponentModel::Container^ components; public: TestControl() { components = gcnew System::ComponentModel::Container; } protected: ~TestControl() { if ( components != nullptr ) { delete components; } } };

System.ComponentModel.Design.ComponentDesigner
System.Windows.Forms.Design.ControlDesigner
System.Windows.Forms.Design.ParentControlDesigner


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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- ControlDesigner クラスのページへのリンク