Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Drawing.Design
Namespace MyPanel
''' <summary>
''' Summary description for MyPanelPageCollection.
''' </summary>
''' <remarks></remarks>
<Editor("System.Web.UI.Design.WebControls.ListItemsCollectionEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", _
GetType(UITypeEditor)), _
PermissionSet(SecurityAction.LinkDemand, Xml:="<PermissionSet class=""System.Security.PermissionSet""" & Chr(13) & Chr(10) & " version=""1"">" & Chr(13) & Chr(10) & _
"<IPermission class=""System.Web.AspNetHostingPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089""" & Chr(13) & Chr(10) & _
" version=""1"" Level=""Minimal""/>" & Chr(13) & Chr(10) & "</PermissionSet>" & Chr(13) & Chr(10) & "")> _
Public Class MyPanelPageCollection
Inherits CollectionBase
#Region "Constructor"
Public Sub New()
End Sub
#End Region
#Region "Indexer"
Default Public Property Item(ByVal index As Object) As MyPanelPage
Get
Dim ind As Integer = IndexOf(index)
If ind < 0 Then
Throw New OutOfRangeException()
End If
Return CType(Me.List(ind), MyPanelPage)
End Get
Set(ByVal value As MyPanelPage)
Me.List(IndexOf(index)) = value
End Set
End Property
#End Region
#Region "Public Methods"
Public Sub Add(ByVal tapPage As MyPanelPage)
Me.List.Add(tapPage)
End Sub
Public Sub Insert(ByVal index As Integer, ByVal tapPage As MyPanelPage)
Me.List.Insert(index, tapPage)
End Sub
Public Sub Remove(ByVal tapPage As MyPanelPage)
Me.List.Remove(tapPage)
End Sub
Public Function Contains(ByVal tapPage As MyPanelPage) As Boolean
Return Me.List.Contains(tapPage)
End Function
''' <summary>
''' Find index of tapPage control based on ID
''' </summary>
''' <param name="obj"></param>
''' <returns></returns>
Public Function IndexOf(ByVal obj As Object) As Integer
If TypeOf obj Is Integer Then
Return CInt(obj)
End If
If TypeOf obj Is String Then
For i As Integer = 0 To List.Count - 1
If CType(Me.List(i), MyPanelPage).ID.ToUpper() = obj.ToString().ToUpper() Then
Return i
End If
Next
Return -1
Else
Throw New InvalidIndexValueException()
End If
End Function
Public Sub CopyTo(ByVal array As MyPanelPage(), ByVal index As Integer)
Me.List.CopyTo(array, index)
End Sub
Public Function Contains(ByVal key As String) As Boolean
Return Me.List.Contains(key)
End Function
Public Sub Remove(ByVal key As String)
Me.List.Remove(key)
End Sub
#End Region
End Class
#Region "exceptions classes"
Class InvalidIndexValueException
Inherits Exception
Public Sub New()
MyBase.New("Invalid Index Value")
End Sub
End Class
Class OutOfRangeException
Inherits Exception
Public Sub New()
MyBase.New("Out Of Range")
End Sub
End Class
#End Region
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.Drawing
Namespace MyPanel
<ToolboxData("<{0}:MyPanelPage runat=server></{0}:MyPanelPage>"), _
ParseChildren(True), _
PersistChildren(False)> _
Public Class MyPanelPage
Inherits System.Web.UI.WebControls.PlaceHolder
#Region "private fields"
Private _title0 As String = String.Empty
Private _title1 As String = String.Empty
Private _title2 As String = String.Empty
Private _height As Unit = 20
Private _width0 As Unit = 100
Private _width1 As Unit = 200
Private _width2 As Unit = 100
Private _verticalAlign As VerticalAlign = VerticalAlign.NotSet
Private _horizontalAlign As HorizontalAlign = HorizontalAlign.NotSet
Private _PanelBody As ITemplate
#End Region
#Region "public properties"
''' <summary>
''' タイトル0
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Title() As String
Get
Return _title0
End Get
Set(ByVal value As String)
_title0 = value
End Set
End Property
''' <summary>
''' タイトル1
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Title1() As String
Get
Return _title1
End Get
Set(ByVal value As String)
_title1 = value
End Set
End Property
''' <summary>
''' タイトル2
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Title2() As String
Get
Return _title2
End Get
Set(ByVal value As String)
_title2 = value
End Set
End Property
''' <summary>
''' 高幅
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Height() As Unit
Get
Return _height
End Get
Set(ByVal value As Unit)
_height = value
End Set
End Property
''' <summary>
''' 列幅0
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Width() As Unit
Get
Return _width0
End Get
Set(ByVal value As Unit)
_width0 = value
End Set
End Property
''' <summary>
''' 列幅1
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Width1() As Unit
Get
Return _width1
End Get
Set(ByVal value As Unit)
_width1 = value
End Set
End Property
''' <summary>
''' 列幅2
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Width2() As Unit
Get
Return _width2
End Get
Set(ByVal value As Unit)
_width2 = value
End Set
End Property
''' <summary>
''' 上下の位置
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property VerticalAlign() As VerticalAlign
Get
Return _verticalAlign
End Get
Set(ByVal value As VerticalAlign)
_verticalAlign = value
End Set
End Property
''' <summary>
''' 左右の位置
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property HorizontalAlign() As HorizontalAlign
Get
Return _horizontalAlign
End Get
Set(ByVal value As HorizontalAlign)
_horizontalAlign = value
End Set
End Property
<PersistenceMode(PersistenceMode.InnerProperty), _
DefaultValue(GetType(ITemplate)), _
Browsable(False)> _
Public Overridable Property PanelBody() As ITemplate
Get
Return _PanelBody
End Get
Set(ByVal value As ITemplate)
_PanelBody = value
End Set
End Property
#End Region
#Region "not implemented properties"
<Browsable(False)> _
Public Overloads Overrides Property EnableTheming() As Boolean
Get
Return MyBase.EnableTheming
End Get
Set(ByVal value As Boolean)
MyBase.EnableTheming = value
End Set
End Property
<Browsable(False)> _
Public Overloads Overrides Property EnableViewState() As Boolean
Get
Return MyBase.EnableViewState
End Get
Set(ByVal value As Boolean)
MyBase.EnableViewState = value
End Set
End Property
<Browsable(False)> _
Public Overloads Overrides Property Visible() As Boolean
Get
Return MyBase.Visible
End Get
Set(ByVal value As Boolean)
MyBase.Visible = value
End Set
End Property
#End Region
End Class
End Namespace
Imports System
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Security.Permissions
Imports System.Web.UI.Design
Imports System.Web.UI.Design.WebControls
Namespace MyPanel
<SecurityPermission(SecurityAction.Demand, UnmanagedCode:=True)> _
Class MyPanelControlDesigner
Inherits CompositeControlDesigner
#Region "privates"
Private Const HEADER_PREFIX As String = "Header"
Private Const CONTENT_PREFIX As String = "Content"
Private panelControl As MyPanelControl
#End Region
#Region "implementations"
Public Overloads Overrides Sub Initialize(ByVal component As IComponent)
' Initialize the base
MyBase.Initialize(component)
panelControl = CType(component, MyPanelControl)
End Sub
Public Overloads Overrides ReadOnly Property AllowResize() As Boolean
Get
Return True
End Get
End Property
Public Overloads Overrides Function GetDesignTimeHtml(ByVal regions As DesignerRegionCollection) As String
Dim i As Integer = 0
'add design regions for all header cells, the region name will be prefixd with
' HEADER_PREFIX, and extended with the tab page index.
For Each tabPage As MyPanelPage In panelControl.PanelPages
regions.Add(New DesignerRegion(Me, HEADER_PREFIX + i.ToString()))
i += 1
Next
' Create an editable region and add it to the regions
' the design region name will take CONTENT_PREFIX as prefix and the index
' of the current active tab.
Dim editableRegion As New EditableDesignerRegion(Me, CONTENT_PREFIX + panelControl.CurrentDesignTab.ToString(), False)
regions.Add(editableRegion)
' Set the highlight for the selected region
regions(panelControl.CurrentDesignTab).Highlight = True
' Use the base class to render the markup
Return MyBase.GetDesignTimeHtml()
End Function
Protected Overloads Overrides Sub CreateChildControls()
MyBase.CreateChildControls()
' Get a reference to the table, which is the first child control
Dim table As Table = CType(panelControl.Controls(0), Table)
' Add design time markers for all cells which represents the tab body
If Not table Is Nothing Then
For i As Integer = 0 To panelControl.PanelPages.Count - 1
table.Rows(0).Cells(i).Attributes(DesignerRegion.DesignerRegionAttributeName) = i.ToString()
Next
'set the editable region
table.Rows(1).Cells(0).Attributes(DesignerRegion.DesignerRegionAttributeName) = (panelControl.PanelPages.Count).ToString()
End If
End Sub
Protected Overloads Overrides Sub OnClick(ByVal e As DesignerRegionMouseEventArgs)
If e.Region Is Nothing Then
Return
End If
' If the clicked region is not a header, return
If e.Region.Name.IndexOf(HEADER_PREFIX) <> 0 Then
Return
End If
' Switch the current view if required
'only when the clicked region is different than the active region.
If e.Region.Name.Substring(HEADER_PREFIX.Length) <> panelControl.CurrentDesignTab.ToString() Then
'extract the index of the design region, and set the CurrentDesignTab index
panelControl.CurrentDesignTab = Integer.Parse(e.Region.Name.Substring(HEADER_PREFIX.Length))
'then after update the design time HTML
MyBase.UpdateDesignTimeHtml()
End If
End Sub
Public Overloads 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)
'only if known host, and we have some panelPages
If (Not host Is Nothing) And (panelControl.PanelPages.Count > 0) Then
'we need to get the contents of the PanelBody of the panelControl
Dim template As ITemplate = panelControl.PanelPages.Item(0).PanelBody
If region.Name.StartsWith(CONTENT_PREFIX) Then
'get the template of the selected tab
'extract the tab index of the edited region, from the region name.
Dim tabIndex As Integer = Integer.Parse(region.Name.Substring(CONTENT_PREFIX.Length))
'switch the design template to the selected tab index.
template = panelControl.PanelPages.Item(tabIndex).PanelBody
End If
' Persist the template in the design host
If Not template Is Nothing Then
Return ControlPersister.PersistTemplate(template, host)
End If
End If
Return [String].Empty
End Function
Public Overloads Overrides Sub SetEditableDesignerRegionContent(ByVal region As EditableDesignerRegion, ByVal content As String)
If content Is Nothing Then
Return
End If
' Get a reference to the designer host
Dim host As IDesignerHost = CType(Component.Site.GetService(GetType(IDesignerHost)), IDesignerHost)
If Not host Is Nothing Then
' Create a template from the content string
Dim template As ITemplate = ControlParser.ParseTemplate(host, content)
If Not template Is Nothing Then
' Determine which region should get the template
If region.Name.StartsWith(CONTENT_PREFIX) Then
Dim tabIndex As Integer = Integer.Parse(region.Name.Substring(CONTENT_PREFIX.Length))
'set back the template for the selected tab body
panelControl.PanelPages.Item(tabIndex).PanelBody = template
End If
End If
End If
End Sub
#End Region
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.ComponentModel
Namespace MyPanel
<ParseChildren(True, "PanelPages"), _
ToolboxData("<{0}:MyPanelControl runat=""server"" Width=""125px"" Height=""100px""></{0}:MyPanelControl>"), _
PersistChildren(False), _
Designer(GetType(MyPanelControlDesigner))> _
Public Class MyPanelControl
Inherits CompositeControl
#Region "private fields"
Private _panelPages As MyPanelPageCollection
Private _currentDesignTab As Integer
#End Region
#Region "public properties"
<PersistenceMode(PersistenceMode.InnerProperty), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
MergableProperty(False)> _
Public ReadOnly Property PanelPages() As MyPanelPageCollection
Get
If _panelPages Is Nothing Then
_panelPages = New MyPanelPageCollection()
End If
Return _panelPages
End Get
End Property
''' <summary>
''' Get or set the deesign time active tab.
''' </summary>
<Browsable(False), _
PersistenceMode(PersistenceMode.InnerProperty), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
Public Property CurrentDesignTab() As Integer
Get
Return _currentDesignTab
End Get
Set(ByVal value As Integer)
_currentDesignTab = value
End Set
End Property
#End Region
#Region "private methods"
''' <summary>
''' BuildTitles:タイトルの内容を作成する
''' </summary>
''' <param name="panelControlTable"></param>
''' <remarks></remarks>
Private Sub BuildTitles(ByRef panelControlTable As Table)
'Create the titles row
Dim titlesRow As New TableRow()
titlesRow.HorizontalAlign = HorizontalAlign.Left
For Each tabPage As MyPanelPage In _panelPages
'Create titles cells
Dim tabTitleCell As New TableCell
tabTitleCell.Height = tabPage.Height
tabTitleCell.Text = tabPage.Title
tabTitleCell.HorizontalAlign = tabPage.HorizontalAlign
tabTitleCell.VerticalAlign = tabPage.VerticalAlign
tabTitleCell.CssClass = "Panel_Title_Backcolor1"
'tabTitleCell.BorderColor = Color.Black
'tabTitleCell.BorderWidth = New Unit("1")
tabTitleCell.Wrap = False
tabTitleCell.Width = tabPage.Width '20081024 何 追加
titlesRow.Cells.Add(tabTitleCell)
'S 20081024 何 追加
tabTitleCell = New TableCell
tabTitleCell.Height = tabPage.Height
tabTitleCell.Text = tabPage.Title1
tabTitleCell.HorizontalAlign = tabPage.HorizontalAlign
tabTitleCell.VerticalAlign = tabPage.VerticalAlign
tabTitleCell.CssClass = "Panel_Title_Backcolor2"
'tabTitleCell.BorderColor = Color.Black
'tabTitleCell.BorderWidth = New Unit("1")
tabTitleCell.Wrap = False
tabTitleCell.Width = tabPage.Width1
titlesRow.Cells.Add(tabTitleCell)
tabTitleCell = New TableCell
tabTitleCell.Height = tabPage.Height
tabTitleCell.Text = tabPage.Title2
tabTitleCell.HorizontalAlign = HorizontalAlign.Right
tabTitleCell.VerticalAlign = tabPage.VerticalAlign
tabTitleCell.CssClass = "Panel_Title_Backcolor3"
'tabTitleCell.BorderColor = Color.Black
'tabTitleCell.BorderWidth = New Unit("1")
tabTitleCell.Wrap = False
tabTitleCell.Width = panelControlTable.Width.Value - tabPage.Width.Value - tabPage.Width1.Value
titlesRow.Cells.Add(tabTitleCell)
Exit For
'E 20081024 何 追加
Next
panelControlTable.Rows.Add(titlesRow)
End Sub
''' <summary>
''' テーブル中の行を作成する
''' </summary>
''' <param name="panelControlTable"></param>
''' <remarks></remarks>
Private Sub BuildContentRows(ByRef panelControlTable As Table)
'Create content row
Dim contentRow As New TableRow
For Each tabPage As MyPanelPage In _panelPages
Dim contentCell As TableCell = BuildContentCell(contentRow)
contentCell.HorizontalAlign = HorizontalAlign.Center
contentCell.VerticalAlign = VerticalAlign.Middle
contentCell.ColumnSpan = 3 '20081024 何 追加
_panelPages.Item(_currentDesignTab).PanelBody.InstantiateIn(contentCell)
contentRow.Cells.Add(contentCell)
Exit For '20081024 何 追加
Next
panelControlTable.Rows.Add(contentRow)
End Sub
''' <summary>
''' テーブル中の列を作成する
''' </summary>
''' <param name="tableRow"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function BuildContentCell(ByRef tableRow As TableRow) As TableCell
Dim tc As New TableCell
tc.CssClass = "Panel_Body_Backcolor"
tc.BorderWidth = New Unit("1")
tc.BorderStyle = WebControls.BorderStyle.Ridge
tc.BorderColor = Color.Black
tc.Height = New Unit("100%")
tableRow.Cells.Add(tc)
Return tc
End Function
#End Region
#Region "implementations"
''' <summary>
''' OnPreRender
''' </summary>
''' <param name="e"></param>
''' <remarks></remarks>
Protected Overloads Overrides Sub OnPreRender(ByVal e As EventArgs)
MyBase.OnPreRender(e)
End Sub
''' <summary>
''' テーブルを作成する
''' </summary>
''' <remarks></remarks>
Protected Overloads Overrides Sub CreateChildControls()
'Always start with a clean form
Controls.Clear()
'Create a table using the control's declarative properties
Dim panelControlTable As New Table()
panelControlTable.CellSpacing = 0
panelControlTable.CellPadding = 0
panelControlTable.Attributes.Add("style", "border-bottom:solid 1px black;")
panelControlTable.BorderStyle = BorderStyle
panelControlTable.Width = Me.Width
panelControlTable.Height = Me.Height
panelControlTable.BackColor = ColorTranslator.FromHtml("inactiveborder")
BuildTitles(panelControlTable)
BuildContentRows(panelControlTable)
'Add the finished panelControlTable to the Controls collection
Controls.Add(panelControlTable)
End Sub
#End Region
End Class
End Namespace