ControlDesigner.ViewControl Propiedad

Definición

Obtiene o establece un control de servidor Web que se puede utilizar para ofrecer una vista previa del formato HTML en tiempo de diseño.

C#
public System.Web.UI.Control ViewControl { get; set; }

Valor de propiedad

Objeto Control utilizado por la clase base para generar el formato HTML en tiempo de diseño.

Ejemplos

En el ejemplo de código siguiente se muestra cómo marcar un diseñador de controles con el SupportsPreviewControlAttribute atributo . El ejemplo de código deriva un control de servidor web de la Label clase y asocia el control a una implementación del diseñador de controles personalizado. La declaración de clase del diseñador de controles se marca con el SupportsPreviewControl atributo establecido trueen . El diseñador de controles invalida el GetDesignTimeHtml método y, a continuación, muestra la Text propiedad del control en cursiva en tiempo de diseño.

C#
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.
    }
}

Comentarios

La ViewControl propiedad usa la UsePreviewControl propiedad para determinar su valor devuelto.

Si la UsePreviewControl propiedad es true, la ViewControl propiedad devuelve una copia temporal del control . Los cambios realizados en el control temporal no se conservan.

Si la UsePreviewControl propiedad es false, la ViewControl propiedad devuelve una instancia de la Component propiedad para el control . Los cambios realizados en la instancia del control se conservan.

El SupportsPreviewControl valor del SupportsPreviewControlAttribute objeto se usa para establecer el valor de la UsePreviewControl propiedad . Por lo tanto, el SupportsPreviewControl valor determina el tipo de control devuelto por la ViewControl propiedad en la clase base ControlDesigner . SupportsPreviewControlAttribute Si no se especifica en la declaración del diseñador de controles, el comportamiento del ControlDesigner objeto equivale a especificar la SupportsPreviewControl propiedad como false.

Se aplica a

Produto Versións
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Consulte también