62,046
社区成员
发帖
与我相关
我的任务
分享
Namespace UI.WebControls
<ToolboxData("<{0}:GameBox runat=""server""></{0}:GameBox>")> _
<Designer(GetType(GameBoxDesigner))> _
Public Class GameBox
Inherits CompositeControl
Implements INamingContainer
Private _template As ITemplate
Public _box As GameBoxContainer
Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Div
End Get
End Property
<PersistenceMode(PersistenceMode.InnerProperty)> _
<DefaultValue(GetType(ITemplate), "")> _
<TemplateContainer(GetType(GameBoxContainer))> _
Public Property View() As ITemplate
Get
Return _template
End Get
Set(ByVal value As ITemplate)
_template = value
End Set
End Property
Protected Overrides Sub CreateChildControls()
Me.Controls.Clear()
_box = New GameBoxContainer
_box.BackColor = Drawing.Color.Beige
If Me.View IsNot Nothing Then
Me.View.InstantiateIn(_box)
End If
Me.Controls.Add(_box)
End Sub
End Class
#Region "容器对象"
Public Class GameBoxContainer
Inherits WebControl
Implements INamingContainer
Protected Overrides ReadOnly Property TagKey() As System.Web.UI.HtmlTextWriterTag
Get
Return HtmlTextWriterTag.Div
End Get
End Property
End Class
#End Region
#Region "设计器"
Public Class GameBoxDesigner
Inherits CompositeControlDesigner
Private mybox As GameBox
Public Overrides Sub Initialize(ByVal component As System.ComponentModel.IComponent)
MyBase.Initialize(component)
mybox = CType(component, GameBox)
End Sub
Protected Overrides Sub CreateChildControls()
mybox.BackColor = Drawing.Color.Red
Dim box As GameBoxContainer = mybox.Controls(0)
box.Attributes.Add(DesignerRegion.DesignerRegionAttributeName, "0")
End Sub
Public Overrides Function GetDesignTimeHtml(ByVal regions As System.Web.UI.Design.DesignerRegionCollection) As String
Dim edit As EditableDesignerRegion = New EditableDesignerRegion(Me, "edit")
regions.Add(edit)
Return MyBase.GetDesignTimeHtml(regions)
End Function
Public Overrides Function GetEditableDesignerRegionContent(ByVal region As System.Web.UI.Design.EditableDesignerRegion) As String
Dim host As IDesignerHost = Component.Site.GetService(GetType(IDesignerHost))
If host IsNot Nothing AndAlso mybox IsNot Nothing Then
Return ControlPersister.PersistTemplate(mybox.View, host)
End If
Return String.Empty
End Function
Public Overrides Sub SetEditableDesignerRegionContent(ByVal region As System.Web.UI.Design.EditableDesignerRegion, ByVal content As String)
If content Is Nothing Then
Return
End If
Dim host As IDesignerHost = Component.Site.GetService(GetType(IDesignerHost))
If host IsNot Nothing Then
mybox.View = ControlParser.ParseTemplate(host, content)
End If
End Sub
End Class
#End Region
End Namespace
<cc1:GameBox ID="GameBox1" runat="server">
<View>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</View>
</cc1:GameBox>