EditableDesignerRegion 클래스

정의

연결된 컨트롤의 디자인 타임 태그 내에 편집 가능한 내용 영역을 나타냅니다.

public ref class EditableDesignerRegion : System::Web::UI::Design::DesignerRegion
public class EditableDesignerRegion : System.Web.UI.Design.DesignerRegion
type EditableDesignerRegion = class
    inherit DesignerRegion
Public Class EditableDesignerRegion
Inherits DesignerRegion
상속
EditableDesignerRegion
파생

예제

이 예제에서는 두 개의 클릭 가능한 영역과 두 개의 뷰 또는 템플릿이 있는 개체를 EditableDesignerRegion 사용하여 컨트롤을 만드는 방법을 보여 줍니다. 프로젝트를 컴파일한 다음 비주얼 디자이너에서 페이지를 열고 디자인으로 전환(WYSIWYG) 보기로 전환합니다. 클릭 가능한 보기는 View1View2 두 개입니다. 보기1CheckBox 클릭하고 페이지 아래쪽에서 클릭 가능한 영역 바로 아래의 빈 디자이너 영역으로 컨트롤을 끕니다. 보기2를 클릭하고 컨트롤을 RadioButton 빈 디자이너 영역으로 끕니다. 보기1을 다시 클릭하면 해당 영역이 CheckBox 다시 나타납니다. 보기2를 클릭하고 가 다시 나타나는 지역을 RadioButton 클릭합니다. 원본 보기로 다시 전환하여 HTML 태그에서 변경 내용이 유지되는 방식을 확인합니다.

참고

프로젝트에 System.Design.dll 어셈블리에 대한 참조가 있어야 합니다.

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

namespace Samples.ASPNet.ControlDesigners_CS 
{
    [
        Designer(typeof(MyMultiRegionControlDesigner)), 
        ToolboxData("<{0}:MyMultiRegionControl runat=\"server\" width=\"200\"></{0}:MyMultiRegionControl>")
    ]
    public class MyMultiRegionControl : CompositeControl
    {
        // Define the templates that represent 2 views on the control
        private ITemplate _view1;
        private ITemplate _view2;

        // Create persistable inner properties 
        // for the two editable views
        [PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(null)]
        public virtual ITemplate View1
        {
            get { return _view1; }
            set { _view1 = value; }
        }
        [PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(null)]
        public virtual ITemplate View2
        {
            get { return _view2; }
            set { _view2 = value; }
        }

        // The current view on the control; 0 = view1, 1 = view2
        private int _currentView = 0;
        public int CurrentView
        {
            get { return _currentView; }
            set { _currentView = value; }
        }

        // Create a simple table with a row of two clickable, 
        // readonly headers and a row with a single column, which 
        // is the 'container' to which we'll be adding controls.
        protected override void CreateChildControls()
        {
            // Always start with a clean form
            Controls.Clear();

            // Create a table using the control's declarative properties
            Table t = new Table();
            t.CellSpacing = 1;
            t.BorderStyle = BorderStyle;
            t.Width = this.Width;
            t.Height = this.Height;

            // Create the header row
            TableRow tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;
            tr.BackColor = Color.LightBlue;

            // Create the first cell in the header row
            TableCell tc = new TableCell();
            tc.Text = "View 1";
            tc.Width = new Unit("50%");
            tr.Cells.Add(tc);

            // Create the second cell in the header row
            tc = new TableCell();
            tc.Text = "View 2";
            tc.Width = new Unit("50%");
            tr.Cells.Add(tc);

            t.Rows.Add(tr);

            // Create the second row for content
            tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;

            // This cell represents our content 'container'
            tc = new TableCell();
            tc.ColumnSpan = 2;

            // Add the current view content to the cell
            // at run-time
            if (!DesignMode)
            {
                Control containerControl = new Control();
                switch (CurrentView)
                {
                    case 0:
                        if (View1 != null)
                            View1.InstantiateIn(containerControl);
                        break;
                    case 1:
                        if (View2 != null)
                            View2.InstantiateIn(containerControl);
                        break;
                }

                tc.Controls.Add(containerControl);
            }

            tr.Cells.Add(tc);

            t.Rows.Add(tr);

            // Add the finished table to the Controls collection
            Controls.Add(t);
        }
    }

    //---------------------------------------------------------
    // Region-based control designer for the above web control, 
    // derived from CompositeControlDesigner.
    public class MyMultiRegionControlDesigner : CompositeControlDesigner 
    {
        private MyMultiRegionControl myControl;

        public override void Initialize(IComponent component)
        {
            base.Initialize(component);
            myControl = (MyMultiRegionControl)component;
        }

        // Make this control resizeable on the design surface
        public override bool AllowResize
        {
            get
            {
                return true;
            }
        }

        // Use the base to create child controls, then add region markers
        protected override void CreateChildControls() {
            base.CreateChildControls();

            // Get a reference to the table, which is the first child control
            Table t = (Table)myControl.Controls[0];

            // Add design time markers for each of the three regions
            if (t != null)
            {
                // View1
                t.Rows[0].Cells[0].Attributes[DesignerRegion.DesignerRegionAttributeName] = "0";
                // View2
                t.Rows[0].Cells[1].Attributes[DesignerRegion.DesignerRegionAttributeName] = "1";
                // Editable region
                t.Rows[1].Cells[0].Attributes[DesignerRegion.DesignerRegionAttributeName] = "2";
            }
        }

        // Handler for the Click event, which provides the region in the arguments.
        protected override void OnClick(DesignerRegionMouseEventArgs e)
        {
            if (e.Region == null)
                return;

            // If the clicked region is not a header, return
            if (e.Region.Name.IndexOf("Header") != 0)
                return;

            // Switch the current view if required
            if (e.Region.Name.Substring(6, 1) != myControl.CurrentView.ToString())
            {
                myControl.CurrentView = int.Parse(e.Region.Name.Substring(6, 1));
                base.UpdateDesignTimeHtml();
            }
        }

        // Create the regions and design-time markup. Called by the designer host.
        public override String GetDesignTimeHtml(DesignerRegionCollection regions) {
            // Create 3 regions: 2 clickable headers and an editable row
            regions.Add(new DesignerRegion(this, "Header0"));
            regions.Add(new DesignerRegion(this, "Header1"));

            // Create an editable region and add it to the regions
            EditableDesignerRegion editableRegion = 
                new EditableDesignerRegion(this, 
                    "Content" + myControl.CurrentView, false);
            regions.Add(editableRegion);

            // Set the highlight for the selected region
            regions[myControl.CurrentView].Highlight = true;

            // Use the base class to render the markup
            return base.GetDesignTimeHtml();
        }

        // Get the content string for the selected region. Called by the designer host?
        public override string GetEditableDesignerRegionContent(EditableDesignerRegion region) 
        {
            // Get a reference to the designer host
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
            if (host != null)
            {
                ITemplate template = myControl.View1;
                if (region.Name == "Content1")
                    template = myControl.View2;

                // Persist the template in the design host
                if (template != null)
                    return ControlPersister.PersistTemplate(template, host);
            }

            return String.Empty;
        }

        // Create a template from the content string and  
        // put it in the selected view.
        public override void SetEditableDesignerRegionContent(EditableDesignerRegion region, string content)
        {
            if (content == null)
                return;

            // Get a reference to the designer host
            IDesignerHost host = (IDesignerHost)Component.Site.GetService(typeof(IDesignerHost));
            if (host != null)
            {
                // Create a template from the content string
                ITemplate template = ControlParser.ParseTemplate(host, content);

                // Determine which region should get the template
                // Either 'Content0' or 'Content1'
                if (region.Name.EndsWith("0"))
                    myControl.View1 = template;
                else if (region.Name.EndsWith("1"))
                    myControl.View2 = template;
            }
        }
    }
}
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Imports System.Web.UI.WebControls

Namespace Samples.ASPNet.ControlDesigners_VB

    < _
        Designer(GetType(MyMultiRegionControlDesigner)), _
        ToolboxData("<{0}:MyMultiRegionControl runat=""server"" width=""200""></{0}:MyMultiRegionControl>") _
    > _
    Public Class MyMultiRegionControl
        Inherits CompositeControl

        ' Define the templates that represent 2 views on the control
        Private _view1 As ITemplate
        Private _view2 As ITemplate
        ' The current view on the control; 0 = view1, 1 = view2
        Private _currentView As Integer = 0

        ' Create persistable inner properties
        <PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(CType(Nothing, ITemplate))> _
        Public Overridable Property View1() As ITemplate
            Get
                Return _view1
            End Get
            Set(ByVal value As ITemplate)
                _view1 = value
            End Set
        End Property

        <PersistenceMode(PersistenceMode.InnerProperty), DefaultValue(CType(Nothing, ITemplate))> _
        Public Overridable Property View2() As ITemplate
            Get
                Return _view2
            End Get
            Set(ByVal value As ITemplate)
                _view2 = value
            End Set
        End Property

        Public Property CurrentView() As Integer
            Get
                Return _currentView
            End Get
            Set(ByVal value As Integer)
                _currentView = value
            End Set
        End Property

        ' Create a simple table with a row of two clickable, 
        ' readonly headers and a row with a single column, which 
        ' is the 'container' to which we'll be adding controls.
        Protected Overrides Sub CreateChildControls()
            ' Start with a clean form
            Controls.Clear()

            ' Create a table
            Dim t As New Table()
            t.CellSpacing = 1
            t.BorderStyle = BorderStyle
            t.Width = Me.Width
            t.Height = Me.Height

            ' Create the header row
            Dim tr As New TableRow()
            tr.HorizontalAlign = HorizontalAlign.Center
            tr.BackColor = Color.LightBlue

            ' Create the first cell in the header row
            Dim tc As New TableCell()
            tc.Text = "View 1"
            tc.Width = New Unit("50%")
            tr.Cells.Add(tc)

            ' Create the second cell in the header row
            tc = New TableCell()
            tc.Text = "View 2"
            tc.Width = New Unit("50%")
            tr.Cells.Add(tc)

            t.Rows.Add(tr)

            ' Create the second row for content
            tr = New TableRow()
            tr.HorizontalAlign = HorizontalAlign.Center

            ' This cell represents our content 'container'
            tc = New TableCell()
            tc.ColumnSpan = 2

            ' Add the current view content to the cell 
            ' at run-time
            If Not DesignMode Then
                Dim containerControl As New Control()
                Select Case CurrentView
                    Case 0
                        If Not (View1 Is Nothing) Then
                            View1.InstantiateIn(containerControl)
                        End If
                    Case 1
                        If Not (View2 Is Nothing) Then
                            View2.InstantiateIn(containerControl)
                        End If
                End Select

                tc.Controls.Add(containerControl)
            End If

            tr.Cells.Add(tc)

            t.Rows.Add(tr)

            ' Add the finished table to the Controls collection
            Controls.Add(t)
        End Sub

    End Class

    ' Region-based control designer for the above web control. 
    ' This is derived from CompositeControlDesigner.
    Public Class MyMultiRegionControlDesigner
        Inherits CompositeControlDesigner

        Private myControl As MyMultiRegionControl

        Public Overrides Sub Initialize(ByVal component As IComponent)
            MyBase.Initialize(component)
            myControl = CType(component, MyMultiRegionControl)
        End Sub

        ' Make this control resizeable on the design surface
        Public Overrides ReadOnly Property AllowResize() As Boolean
            Get
                Return True
            End Get
        End Property

        ' Use the base to create child controls, then add region markers
        Protected Overrides Sub CreateChildControls()
            MyBase.CreateChildControls()

            ' Get a reference to the table, which is the first child control
            Dim t As Table
            t = CType(myControl.Controls(0), Table)

            ' Add design time markers for each of the three regions
            If Not IsNothing(t) Then
                ' View1
                t.Rows(0).Cells(0).Attributes(DesignerRegion.DesignerRegionAttributeName) = "0"
                ' View2
                t.Rows(0).Cells(1).Attributes(DesignerRegion.DesignerRegionAttributeName) = "1"
                ' Editable region
                t.Rows(1).Cells(0).Attributes(DesignerRegion.DesignerRegionAttributeName) = "2"
            End If
        End Sub

        ' Handler for the Click event, which provides the region in the arguments.
        Protected Overrides Sub OnClick(ByVal e As DesignerRegionMouseEventArgs)
            If IsNothing(e.Region) Then
                Return
            End If

            ' If the clicked region is not a header, return
            If e.Region.Name.IndexOf("Header") <> 0 Then
                Return
            End If

            ' Switch the current view if required
            If e.Region.Name.Substring(6, 1) <> myControl.CurrentView.ToString() Then
                myControl.CurrentView = Integer.Parse(e.Region.Name.Substring(6, 1))
                MyBase.UpdateDesignTimeHtml()
            End If
        End Sub

        ' Create the regions and design-time markup. Called by the designer host.
        Public Overrides Function GetDesignTimeHtml(ByVal regions As DesignerRegionCollection) As String
            ' Create 3 regions: 2 clickable headers and an editable row
            regions.Add(New DesignerRegion(Me, "Header0"))
            regions.Add(New DesignerRegion(Me, "Header1"))

            ' Create an editable region and add it to the regions
            Dim editableRegion As EditableDesignerRegion = _
                New EditableDesignerRegion(Me, _
                    "Content" & myControl.CurrentView, False)
            regions.Add(editableRegion)

            ' Set the highlight for the selected region
            regions(myControl.CurrentView).Highlight = True

            ' Use the base class to render the markup
            Return MyBase.GetDesignTimeHtml()
        End Function

        ' Get the content string for the selected region. Called by the designer host?
        Public Overrides Function GetEditableDesignerRegionContent(ByVal region As EditableDesignerRegion) As String
            ' Get a reference to the designer host
            Dim host As IDesignerHost = CType(Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)

            If Not IsNothing(host) Then
                Dim template As ITemplate = myControl.View1
                If region.Name = "Content1" Then
                    template = myControl.View2
                End If

                ' Persist the template in the design host
                If Not IsNothing(template) Then
                    Return ControlPersister.PersistTemplate(template, host)
                End If
            End If

            Return String.Empty
        End Function

        ' Create a template from the content string and put it 
        ' in the selected view. Called by the designer host?
        Public Overrides Sub SetEditableDesignerRegionContent(ByVal region As EditableDesignerRegion, ByVal content As String)
            If IsNothing(content) Then
                Return
            End If

            ' Get a reference to the designer host
            Dim host As IDesignerHost = CType(Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
            If Not IsNothing(host) Then
                ' Create a template from the content string
                Dim template As ITemplate = ControlParser.ParseTemplate(host, content)

                ' Determine which region should get the template
                If region.Name.EndsWith("0") Then
                    myControl.View1 = template
                ElseIf region.Name.EndsWith("1") Then
                    myControl.View2 = template
                End If

            End If
        End Sub
    End Class

End Namespace
<%@ Page Language="C#"  %>
<%@ Register TagPrefix="aspSample" 
    Assembly="Samples.ASPNet.ControlDesigners_CS" 
    Namespace="Samples.ASPNet.ControlDesigners_CS" %>

<!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>Designers Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <aspSample:MyMultiRegionControl ID="myCtl" Runat=Server Width=200 Height=75 BorderStyle=solid >
        </aspSample:MyMultiRegionControl><br />
        <asp:CheckBox ID="CheckBox1" runat="server" />
        <asp:RadioButton ID="RadioButton1" runat="server" />

    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="aspSample" 
    Assembly="Samples.ASPNet.ControlDesigners_VB" 
    Namespace="Samples.ASPNet.ControlDesigners_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>Designers Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <aspSample:MyMultiRegionControl ID="myCtl" Runat=Server Width=200 Height=75 BorderStyle=solid >
        </aspSample:MyMultiRegionControl><br />
        <asp:CheckBox ID="CheckBox1" runat="server" />
        <asp:RadioButton ID="RadioButton1" runat="server" />

    </div>
    </form>
</body>
</html>

설명

클래스를 EditableDesignerRegion 사용하여 디자인 타임에 템플릿을 관리할 수 있습니다. 는 ControlDesigner 메서드와 함께 GetEditableDesignerRegionContent 이 클래스의 instance 사용하여 지역 콘텐츠의 HTML 태그를 생성합니다.

생성자

EditableDesignerRegion(ControlDesigner, String)

제공된 소유자와 이름을 사용하여 EditableDesignerRegion 클래스의 새 인스턴스를 초기화합니다.

EditableDesignerRegion(ControlDesigner, String, Boolean)

제공된 소유자 및 이름과 EditableDesignerRegion 속성의 초기 값을 사용하여 ServerControlsOnly 클래스의 새 인스턴스를 만듭니다.

속성

Content

영역 내용에 대한 HTML 태그를 가져오거나 설정합니다.

Description

디자이너 영역에 대한 설명을 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)
Designer

연결된 디자이너 구성 요소를 가져옵니다.

(다음에서 상속됨 DesignerObject)
DisplayName

디자이너 영역의 표시 이름을 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)
EnsureSize

디자인 호스트가 디자이너 영역에서 영역 크기를 명시적으로 설정해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)
Highlight

디자인 화면에서 디자이너 영역을 강조 표시해야 하는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)
Name

개체의 이름을 가져옵니다.

(다음에서 상속됨 DesignerObject)
Properties

개체의 속성을 가져옵니다.

(다음에서 상속됨 DesignerObject)
Selectable

디자인 화면에서 사용자가 디자이너 영역을 선택할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)
Selected

디자인 화면에서 디자이너 영역이 현재 선택되어 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)
ServerControlsOnly

영역에 웹 서버 컨트롤만 허용할지 여부를 나타내는 값을 가져오거나 설정합니다.

SupportsDataBinding

영역을 데이터 소스에 바인딩할 수 있는지 여부를 나타내는 값을 가져오거나 설정합니다.

UserData

디자이너 영역과 연결된 선택적 사용자 데이터를 가져오거나 설정합니다.

(다음에서 상속됨 DesignerRegion)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBounds()

디자인 화면의 디자이너 영역 크기를 검색합니다.

(다음에서 상속됨 DesignerRegion)
GetChildViewRendering(Control)

제공된 컨트롤의 디자인 타임 HTML 태그가 포함된 ViewRendering 개체를 반환합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetService(Type)

제공된 형식으로 식별되는 서비스를 디자인 호스트에서 가져옵니다.

(다음에서 상속됨 DesignerObject)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

IServiceProvider.GetService(Type)

이 멤버에 대한 설명은 GetService(Type)를 참조하세요.

(다음에서 상속됨 DesignerObject)

확장 메서드

GetKeyedService<T>(IServiceProvider, Object)

에서 형식 T 의 서비스를 가져옵니다 IServiceProvider.

GetKeyedServices(IServiceProvider, Type, Object)

에서 형식 serviceType 의 서비스 열거형을 IServiceProvider가져옵니다.

GetKeyedServices<T>(IServiceProvider, Object)

에서 형식 T 의 서비스 열거형을 IServiceProvider가져옵니다.

GetRequiredKeyedService(IServiceProvider, Type, Object)

에서 형식 serviceType 의 서비스를 가져옵니다 IServiceProvider.

GetRequiredKeyedService<T>(IServiceProvider, Object)

에서 형식 T 의 서비스를 가져옵니다 IServiceProvider.

CreateAsyncScope(IServiceProvider)

범위 서비스를 확인하는 데 사용할 수 있는 새 AsyncServiceScope를 만듭니다.

CreateScope(IServiceProvider)

범위 서비스를 확인하는 데 사용할 수 있는 새 IServiceScope를 만듭니다.

GetRequiredService(IServiceProvider, Type)

IServiceProvider에서 serviceType 형식의 서비스를 가져옵니다.

GetRequiredService<T>(IServiceProvider)

IServiceProvider에서 T 형식의 서비스를 가져옵니다.

GetService<T>(IServiceProvider)

IServiceProvider에서 T 형식의 서비스를 가져옵니다.

GetServices(IServiceProvider, Type)

IServiceProvider에서 serviceType 형식의 서비스 열거형을 가져옵니다.

GetServices<T>(IServiceProvider)

IServiceProvider에서 T 형식의 서비스 열거형을 가져옵니다.

GetFakeLogCollector(IServiceProvider)

가짜 로거로 전송된 로그 레코드를 수집하는 개체를 가져옵니다.

GetFakeRedactionCollector(IServiceProvider)

종속성 주입 컨테이너에서 가짜 재배포기 수집기 instance 가져옵니다.

적용 대상

추가 정보