ControlDesigner.ViewControl 속성

정의

디자인 타임 HTML 태그를 미리 보는 데 사용할 수 있는 웹 서버 컨트롤을 가져오거나 설정합니다.

public:
 property System::Web::UI::Control ^ ViewControl { System::Web::UI::Control ^ get(); void set(System::Web::UI::Control ^ value); };
public System.Web.UI.Control ViewControl { get; set; }
member this.ViewControl : System.Web.UI.Control with get, set
Public Property ViewControl As Control

속성 값

Control

기본 클래스에서 디자인 타임 HTML 태그를 생성하는 데 사용되는 Control 개체입니다.

예제

다음 코드 예제에서는 컨트롤 디자이너를 표시 하는 방법에 설명 합니다 SupportsPreviewControlAttribute 특성입니다. 코드 예제에서는 클래스에서 웹 서버 컨트롤을 Label 파생 하 고 사용자 지정 컨트롤 디자이너 구현에 컨트롤을 연결 합니다. 컨트롤 디자이너 클래스 선언으로 표시 되는 SupportsPreviewControl 특성이 설정 true합니다. 컨트롤 디자이너는 메서드를 GetDesignTimeHtml 재정의한 다음 디자인 타임에 컨트롤의 속성을 기울임꼴로 표시합니다 Text .

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

설명

속성은 ViewControl 속성을 사용하여 UsePreviewControl 반환 값을 결정합니다.

속성이 UsePreviewControl trueViewControl 면 컨트롤의 임시 복사본을 반환합니다. 임시 컨트롤에 변경 내용이 유지 되지 않습니다.

속성이 UsePreviewControl false면 컨트롤에 ViewControl 대한 속성의 인스턴스를 Component 반환합니다. 컨트롤 인스턴스에 대한 변경 내용은 유지됩니다.

SupportsPreviewControl 개체의 SupportsPreviewControlAttribute 설정은 속성 값을 UsePreviewControl 설정하는 데 사용됩니다. 따라서 설정은 SupportsPreviewControl 기본 ControlDesigner 클래스의 속성에 의해 ViewControl 반환되는 컨트롤의 형식을 결정합니다. SupportsPreviewControlAttribute 컨트롤 디자이너 선언 ControlDesigner 에 지정 되지 않은 경우 개체 동작으로 속성을 false지정 하는 SupportsPreviewControl 것과 같습니다.

적용 대상

추가 정보