SupportsPreviewControlAttribute 类

定义

指示在设计时控制设计器是否需要控件的预览实例。Indicates whether a control designer requires a preview instance of the control at design time. 此类不能被继承。This class cannot be inherited.

public ref class SupportsPreviewControlAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class SupportsPreviewControlAttribute : Attribute
type SupportsPreviewControlAttribute = class
    inherit Attribute
Public NotInheritable Class SupportsPreviewControlAttribute
Inherits Attribute
继承
SupportsPreviewControlAttribute
属性

示例

下面的代码示例演示如何使用SupportsPreviewControlAttribute属性标记控件设计器。The following code example demonstrates how to mark a control designer with the SupportsPreviewControlAttribute attribute. 此代码示例从Label类派生 ASP.NET 服务器控件, 并将 ASP.NET 服务器控件与自定义控件设计器实现相关联。The code example derives an ASP.NET server control from the Label class and associates the ASP.NET server control with a custom control designer implementation. 控件设计器类声明标记SupportsPreviewControl为特性设置为。 trueThe control designer class declaration is marked with the SupportsPreviewControl attribute set to true. 控件设计器将重GetDesignTimeHtml写方法, 并将控件的设计时 HTML 用斜体标记括起来。The control designer overrides the GetDesignTimeHtml method and encloses the design-time HTML for the control in italic tags.

using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.Design.WebControls;
using System.Web.UI.WebControls;
using System.Reflection;

namespace ControlDesignerSamples.CS
{
    // Define a simple designer associated with a 
    // simple text web control.
    
    // Mark the designer with the SupportsPreviewControlAttribute set
    // to true.  This means the base.UsePreviewControl returns true,
    // and base.ViewControl returns a temporary preview copy of the control.
    [SupportsPreviewControl(true)]
    public class SimpleTextControlDesigner : TextControlDesigner
    {		
        // Override the base GetDesignTimeHtml method to display 
        // the design time text in italics.
        public override string GetDesignTimeHtml()
        {
            string html = String.Empty;
 
            try
            {
                // Initialize the return string to the default
                // design time html of the base TextControlDesigner.
                html = base.GetDesignTimeHtml();

                // Get the ViewControl for the associated control.
                Label ctrl = (Label)ViewControl;

                ctrl.Style.Add(HtmlTextWriterStyle.FontStyle, "Italic");
                html = base.GetDesignTimeHtml();
            }
            catch (System.Exception e)
            {
               if (String.IsNullOrEmpty(html))
               {
                   html = GetErrorDesignTimeHtml(e);
               }
            }
            
            return html;
        }
    }

    // Derive a simple Web control from Label to render a text string.
    // Associate this control with the SimpleTextControlDesigner.
    [DesignerAttribute("ControlDesignerSamples.CS.SimpleTextControlDesigner"),
    ToolboxData("<{0}:MyLabelControl Runat=\"Server\"><{0}:MyLabelControl>")]
    public class MyLabelControl : Label
    {
        // Use the Label control implementation, but associate
        // the derived class with the custom control designer.
    }
}
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls
Imports System.Reflection

Namespace ControlDesignerSamples.VB

    ' Derive a simple Web control from Label to render a text string.
    ' Associate this control with the SimpleTextControlDesigner.
    <DesignerAttribute("ControlDesignerSamples.CS.SimpleTextControlDesigner"), _
    ToolboxData("<{0}:MyLabelControl Runat=""Server""><{0}:MyLabelControl>")> _
    Public Class MyLabelControl
        Inherits Label

        ' Use the Label control implementation, but associate
        ' the derived class with the custom control designer.
    End Class


    ' Mark the designer with the SupportsPreviewControlAttribute set
    ' to true.  This means the base.UsePreviewControl returns true,
    ' and base.ViewControl returns a temporary preview copy of the control.
    <SupportsPreviewControl(True)> _
    Public Class SimpleTextControlDesigner
        Inherits TextControlDesigner

        ' Override the base GetDesignTimeHtml method to display 
        ' the design time text in italics.
        Public Overrides Function GetDesignTimeHtml() As String
            Dim html As String = String.Empty

            Try
                ' Get the ViewControl for the associated control.
                Dim ctrl As Label = CType(ViewControl, Label)

                ' Set the default text, if necessary
                If ctrl.Text.Length = 0 Then
                    ctrl.Text = "Sample Text"
                End If

                ' Set the style to italic
                ctrl.Style.Add(HtmlTextWriterStyle.FontStyle, "italic")

                ' Let the base class create the HTML markup
                html = MyBase.GetDesignTimeHtml()
            Catch ex As Exception
                If String.IsNullOrEmpty(html) Then
                    ' Display the exception message
                    html = GetErrorDesignTimeHtml(ex)
                End If
            End Try

            Return html
        End Function

    End Class
End Namespace

注解

SupportsPreviewControlAttribute将特性应用于控件设计器类, 以指示控件设计器支持的预览控件类型。Apply the SupportsPreviewControlAttribute attribute to a control designer class to indicate the type of preview control that is supported by the control designer. 使用此属性可更改设计时呈现的预览控件, 而不会影响关联控件的实际持久化实例。Use this attribute to change a preview control for design-time rendering without affecting the actual persisted instance of the associated control.

通常, 在声明SupportsPreviewControlAttribute ControlDesigner从类派生的自定义设计器类时指定。Typically, you specify the SupportsPreviewControlAttribute when declaring a custom designer class that is derived from the ControlDesigner class. SupportsPreviewControlAttribute特性的SupportsPreviewControl属性ViewControlUsePreviewControl决定基类ControlDesigner中和成员的行为。The value of the SupportsPreviewControl property for the SupportsPreviewControlAttribute attribute determines the behavior for the UsePreviewControl and ViewControl members in the base ControlDesigner class.

将属性设置为true , 以指示设计器使用关联控件的临时副本来生成设计时 HTML。 SupportsPreviewControlSet the SupportsPreviewControl property to true to indicate that the designer uses a temporary copy of the associated control to generate the design-time HTML. 对临时控件所做的更改不会持久保存。Changes to the temporary control are not persisted.

将属性设置为false , 以指示设计器从ViewControl方法返回Component控件实例 (具体为属性)。 SupportsPreviewControlSet the SupportsPreviewControl property to false to indicate that the designer returns the control instance, specifically the Component property, from the ViewControl method. 更改对控件对象的更改。Changes to the control object are persisted.

例如, CalendarDesigner类被标记为, SupportsPreviewControlAttribute并将设置为trueFor example, the CalendarDesigner class is marked with the SupportsPreviewControlAttribute set to true. 设计器将预览控件与自动样式格式设置任务一起使用, 这允许用户预览可应用于日历的各种自动套用格式 stylesthat。The designer uses the preview control with the automatic style formatting task, which allows the user to preview various autoformat stylesthat can be applied to the calendar. 当用户在用户界面中选择不同的自动套用格式样式时, 所选样式方案将应用于预览控件。As the user selects different autoformat styles in the user interface, the selected style scheme is applied to the preview control. 将新样式应用于预览控件不会更改应用于设计器中的Calendar控件实例的方案。Applying a new style to the preview control does not change the scheme that is applied to the instance of the Calendar control in the designer.

如果未在控件设计器声明中指定, 则此ControlDesigner行为等效于将指定SupportsPreviewControlfalseSupportsPreviewControlAttributeIf the SupportsPreviewControlAttribute is not specified in the control designer declaration, the ControlDesigner behavior is equivalent to specifying the SupportsPreviewControl as false.

备注

派生自ControlDesigner类的设计器类可以UsePreviewControl重写ViewControl和成员, 并忽略SupportsPreviewControlAttribute该特性。Designer classes derived from the ControlDesigner class can override the UsePreviewControl and ViewControl members, and ignore the SupportsPreviewControlAttribute attribute. 若要确定ViewControlUsePreviewControl的预期行为, 请参见派生控件设计器类的参考文档。To determine the expected behavior for ViewControl and UsePreviewControl, see the reference documentation for the derived control designer class.

有关使用属性的常规信息, 请参阅属性概述特性For general information about using attributes, see Attributes Overview and Attributes. 有关设计时特性的详细信息, 请参阅特性和设计时支持For more information about design-time attributes, see Attributes and Design-Time Support.

构造函数

SupportsPreviewControlAttribute(Boolean)

初始化 SupportsPreviewControlAttribute 类的新实例,并设置 SupportsPreviewControl 属性的初始值。Initializes a new instance of the SupportsPreviewControlAttribute class and sets the initial value of the SupportsPreviewControl property.

字段

Default

获取设置为默认预览值的 SupportsPreviewControlAttribute 类的实例。Gets an instance of the SupportsPreviewControlAttribute class that is set to the default preview value. 此字段为只读。This field is read-only.

属性

SupportsPreviewControl

获取一个指示设计时控件设计器是否需要临时预览控件的值。Gets a value indicating whether the control designer requires a temporary preview control at design time.

TypeId

在派生类中实现时,获取此 Attribute 的唯一标识符。When implemented in a derived class, gets a unique identifier for this Attribute.

(继承自 Attribute)

方法

Equals(Object)

确定指定的对象表示的预览特性设置是否与 SupportsPreviewControlAttribute 类当前实例的设置相同。Determines whether the specified object represents the same preview attribute setting as the current instance of the SupportsPreviewControlAttribute class.

GetHashCode()

返回 SupportsPreviewControlAttribute 类的此实例的哈希代码。Returns the hash code for this instance of the SupportsPreviewControlAttribute class.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IsDefaultAttribute()

指示 SupportsPreviewControlAttribute 类的当前实例是否设置为默认的预览特性值。Indicates whether the current instance of the SupportsPreviewControlAttribute class is set to the default preview attribute value.

Match(Object)

当在派生类中重写时,返回一个指示此实例是否等于指定对象的值。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(继承自 Attribute)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式接口实现

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

将一组名称映射为对应的一组调度标识符。Maps a set of names to a corresponding set of dispatch identifiers.

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,然后可以使用该信息获取接口的类型信息。Retrieves the type information for an object, which can be used to get the type information for an interface.

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对某一对象公开的属性和方法的访问。Provides access to properties and methods exposed by an object.

(继承自 Attribute)

适用于

另请参阅