ControlDesigner クラスとは? わかりやすく解説

ControlDesigner クラス

Web サーバー コントロールデザイン モード動作拡張するための基本コントロール デザイナ クラス提供します

名前空間: System.Web.UI.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Class ControlDesigner
    Inherits HtmlControlDesigner
Dim instance As ControlDesigner
public class ControlDesigner : HtmlControlDesigner
public ref class ControlDesigner : public
 HtmlControlDesigner
public class ControlDesigner extends HtmlControlDesigner
public class ControlDesigner extends
 HtmlControlDesigner
解説解説

ControlDesigner クラスは、Visual Studio 2005 などのデザイン ホストで、デザイン時に Web サーバー コントロールサポートするために継承および拡張できる基本コントロール デザイナ クラス提供します

デザイン時の表示処理するオブジェクト モデルは、以前のバージョン比べて強化されており、簡略化されたオブジェクト モデルアクセスできるようにするために、次の新し基本クラス追加されています。

オートフォーマット
アクション リスト (スマート タグ)
コントロール デザイナ領域
テンプレート
デザイン時の表示

ControlDesigner クラスには、Web サーバー コントロールデザイン時の表示サポートする次のようなメソッドあります。これらのメソッドのほとんどは、以前のバージョンと同じです。

使用例使用例

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>
.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
   System.ComponentModel.Design.ComponentDesigner
     System.Web.UI.Design.HtmlControlDesigner
      System.Web.UI.Design.ControlDesigner
         派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ControlDesigner クラス

Controlデザイン モード動作拡張します。

名前空間: System.Windows.Forms.Design
アセンブリ: System.Design (system.design.dll 内)
構文構文

Public Class ControlDesigner
    Inherits ComponentDesigner
Dim instance As ControlDesigner
public class ControlDesigner : ComponentDesigner
public ref class ControlDesigner : public
 ComponentDesigner
public class ControlDesigner extends ComponentDesigner
public class ControlDesigner extends
 ComponentDesigner
解説解説
使用例使用例

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.Object
   System.ComponentModel.Design.ComponentDesigner
    System.Windows.Forms.Design.ControlDesigner
       System.Windows.Forms.Design.ParentControlDesigner
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ControlDesigner メンバ
System.Windows.Forms.Design 名前空間
ComponentDesigner
IDesigner
DesignerAttribute
その他の技術情報
デザインサポート拡張



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ControlDesigner クラス」の関連用語

ControlDesigner クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ControlDesigner クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS