SupportsPreviewControlAttribute Klasa

Definicja

Wskazuje, czy projektant kontrolek wymaga wystąpienia podglądu kontrolki w czasie projektowania. Klasa ta nie może być dziedziczona.

public ref class SupportsPreviewControlAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class)]
public sealed class SupportsPreviewControlAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class)>]
type SupportsPreviewControlAttribute = class
    inherit Attribute
Public NotInheritable Class SupportsPreviewControlAttribute
Inherits Attribute
Dziedziczenie
SupportsPreviewControlAttribute
Atrybuty

Przykłady

W poniższym przykładzie kodu pokazano, jak oznaczyć projektanta kontrolek atrybutem SupportsPreviewControlAttribute . Przykładowy kod pochodzi ASP.NET kontroli serwera z Label klasy i kojarzy kontrolkę serwera ASP.NET z implementacją niestandardowego projektanta sterowania. Deklaracja klasy projektanta kontrolek jest oznaczona atrybutem ustawionym SupportsPreviewControl na true. Projektant kontrolek zastępuje metodę GetDesignTimeHtml i zawiera kod HTML czasu projektowania dla kontrolki w tagach kursywy.

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

Uwagi

SupportsPreviewControlAttribute Zastosuj atrybut do klasy projektanta kontrolek, aby wskazać typ kontrolki podglądu obsługiwanej przez projektanta kontrolek. Ten atrybut umożliwia zmianę kontrolki podglądu renderowania w czasie projektowania bez wpływu na rzeczywiste utrwalone wystąpienie skojarzonej kontrolki.

Zazwyczaj podczas SupportsPreviewControlAttribute deklarowania klasy projektanta niestandardowego, która pochodzi z ControlDesigner klasy . Wartość SupportsPreviewControl właściwości atrybutu SupportsPreviewControlAttribute określa zachowanie elementów UsePreviewControl członkowskich i ViewControl w klasie bazowej ControlDesigner .

SupportsPreviewControl Ustaw właściwość na true , aby wskazać, że projektant używa tymczasowej kopii skojarzonej kontrolki do wygenerowania kodu HTML w czasie projektowania. Zmiany w kontrolce tymczasowej nie są utrwalane.

SupportsPreviewControl Ustaw właściwość na , aby wskazaćfalse, że projektant zwraca wystąpienie kontrolki, w szczególności Component właściwość, z ViewControl metody . Zmiany obiektu sterującego są utrwalane.

Na przykład CalendarDesigner klasa jest oznaczona za pomocą SupportsPreviewControlAttribute zestawu na truewartość . Projektant używa kontrolki podglądu z automatycznym zadaniem formatowania stylu, które umożliwia użytkownikowi wyświetlanie podglądu różnych stylów autoformatowania, które można zastosować do kalendarza. Gdy użytkownik wybiera różne style autoformatowania w interfejsie użytkownika, wybrany schemat stylów jest stosowany do kontrolki podglądu. Zastosowanie nowego stylu do kontrolki podglądu nie zmienia schematu stosowanego Calendar do wystąpienia kontrolki w projektancie.

Jeśli parametr SupportsPreviewControlAttribute nie jest określony w deklaracji projektanta kontrolek, ControlDesigner zachowanie jest równoważne określeniu SupportsPreviewControl elementu jako false.

Uwaga

Klasy projektanta pochodzące z ControlDesigner klasy mogą zastąpić UsePreviewControl elementy członkowskie i ViewControl i ignorować SupportsPreviewControlAttribute atrybut . Aby określić oczekiwane zachowanie dla ViewControl elementów i UsePreviewControl, zapoznaj się z dokumentacją referencyjną dla klasy pochodnego projektanta kontrolek.

Aby uzyskać ogólne informacje na temat używania atrybutów, zobacz Omówienie atrybutów i atrybuty. Aby uzyskać więcej informacji na temat atrybutów czasu projektowania, zobacz Atrybuty i obsługa Design-Time.

Konstruktory

SupportsPreviewControlAttribute(Boolean)

Inicjuje SupportsPreviewControlAttribute nowe wystąpienie klasy i ustawia początkową wartość SupportsPreviewControl właściwości.

Pola

Default

Pobiera wystąpienie SupportsPreviewControlAttribute klasy ustawionej na domyślną wartość podglądu. To pole jest tylko do odczytu.

Właściwości

SupportsPreviewControl

Pobiera wartość wskazującą, czy projektant kontrolek wymaga tymczasowej kontrolki podglądu w czasie projektowania.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

Określa, czy określony obiekt reprezentuje to samo ustawienie atrybutu podglądu co bieżące wystąpienie SupportsPreviewControlAttribute klasy.

GetHashCode()

Zwraca kod skrótu dla tego wystąpienia SupportsPreviewControlAttribute klasy.

GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

Wskazuje, czy bieżące wystąpienie SupportsPreviewControlAttribute klasy jest ustawione na domyślną wartość atrybutu podglądu.

Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

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

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też