ControlDesigner Class
Assembly: System.Design (in system.design.dll)
The ControlDesigner class provides a base control designer class that can be inherited from and extended to provide design-time support for a Web server control in a design host, such as Visual Studio 2005.
The object model for working with design-time rendering is improved over earlier versions, with the following new base classes to provide access to the simplified object model:
-
ControlDesigner, which is not new, but has been greatly improved.
Automatic Formatting
You can create a variety of automatic and pre-defined formats that can simplify the process of page developers who are applying complex style changes to custom Web server controls. For example, the TableDesigner control, which derives from the ControlDesigner class, provides many automatic formats from which to choose. To implement and provide automatic formatting in your custom controls, use the following features:
-
The AutoFormats property.
-
The OnAutoFormatApplied method.
-
The DesignerAutoFormat class.
-
The DesignerAutoFormatStyle class.
Action Lists (Smart Tags)
Action lists are menus of important or widely used tasks that a page developer who uses a control can perform in a design-time user interface (UI), such as Visual Studio 2005. For example, the design-time view of your control could provide a menu of available tasks. This includes a task to format the control automatically. To learn about action lists, start with the following features:
-
The ActionLists property.
-
The DesignerActionList class.
-
The GetSortedActionItems method.
-
The DesignerActionListCollection class.
-
The DesignerActionMethodItem class.
-
The DesignerActionPropertyItem class.
Control Designer Regions
Regions are editable areas in the design-time view of a Web server control. This feature offers WYSIWYG-like editing of the template content, inner controls, and properties at design time. You can have the control designer create controls in regions or you can use the Toolbox to drag and drop controls into regions. Regions are managed with the following features:
-
The OnClick method.
-
The DesignerRegion class.
-
The EditableDesignerRegion class.
-
The GetEditableDesignerRegionContent method.
-
The SetEditableDesignerRegionContent method.
Templates
The model for creating a UI for design-time editing of templated controls, such as the GridView control, has been greatly improved from earlier versions. You can create complex custom controls that include templates for various parts of the control, and your custom control designer can help page developers who are modifying templates with the following features:
-
The TemplateGroups property.
-
The InTemplateMode property.
-
The TemplateGroup class.
Design-Time Rendering
The ControlDesigner class has the following methods to support design-time rendering of the Web server control. Most of these methods are the same as in earlier versions:
-
The GetDesignTimeHtml method.
-
The GetEmptyDesignTimeHtml method.
-
The GetErrorDesignTimeHtml method.
-
The UpdateDesignTimeHtml method.
-
The CreatePlaceHolderDesignTimeHtml method.
The following code example demonstrates how to create a simple designer class that derives from the ControlDesigner class. This control designer supports a custom TextControl class and provides a command to change the text size of a control at design time. The control designer is associated with the control by specifying the control designer in a DesignerAttribute object declaration on the TextControl class. The key to persisting property changes from the control designer to the HTML markup is found in the ToggleTextSize method of the custom ActionList class.
To try the example, add a reference to the System.Design.dll assembly and compile the code.
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 ... <%@ 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 xmlns="http://www.w3.org/1999/xhtml" > <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>
- SecurityPermission for calling unmanaged code. Demand value: Demand; Associated enumeration: UnmanagedCode.
System.ComponentModel.Design.ComponentDesigner
System.Web.UI.Design.HtmlControlDesigner
System.Web.UI.Design.ControlDesigner
Derived Classes
Reference
ControlDesigner MembersSystem.Web.UI.Design Namespace
TemplateGroup
DesignerAutoFormat
DesignerActionList
DesignerRegion
ContainerControlDesigner
CompositeControlDesigner
Other Resources
Introduction to ASP.NET Control DesignersDesign-Time Architecture
Design-Time Support for Web Forms
Sample Control Designer with Action Lists and Services