由于项目需要,想把一个按钮区域封装成自定义控件方便分发给项目其他人
按钮栏控件有两个区域需要在设计时允许拖放控件,看了MSDN以及在网上找了些资料
虽然实现了多编辑区域的效果,但测试时发现一个问题,就是添加进入的按钮,成了该工具栏的子控件,得通过FindControl("按钮名称")来查找得到,不象Panel或是Wizard,控件拖放进入后,但依然可以在代码页中进入通过该控件ID访问此控件。
以下是写的测试代码:
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