Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Security.Permissions
Imports System.Drawing.Design
Namespace AdvControls
''' <summary>
''' Summary description for MyTabPageCollection.
''' </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 MyTabPageCollection
Inherits CollectionBase
#Region "Constructor"
Public Sub New()
End Sub
#End Region
#Region "Indexer"
Default Public Property Item(ByVal index As Object) As MyTabPage
Get
Dim ind As Integer = IndexOf(index)
If ind < 0 Then
Throw New OutOfRangeException()
End If
Return CType(Me.List(ind), MyTabPage)
End Get
Set(ByVal value As MyTabPage)
Me.List(IndexOf(index)) = value
End Set
End Property
#End Region
#Region "Public Methods"
Public Sub Add(ByVal tapPage As MyTabPage)
Me.List.Add(tapPage)
End Sub
Public Sub Insert(ByVal index As Integer, ByVal tapPage As MyTabPage)
Me.List.Insert(index, tapPage)
End Sub
Public Sub Remove(ByVal tapPage As MyTabPage)
Me.List.Remove(tapPage)
End Sub
Public Function Contains(ByVal tapPage As MyTabPage) 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), MyTabPage).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 MyTabPage(), 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 AdvControls
<ToolboxData("<{0}:MyTabPage runat=server></{0}:MyTabPage>"), _
ParseChildren(True), _
PersistChildren(False)> _
Public Class MyTabPage
Inherits System.Web.UI.WebControls.PlaceHolder
#Region "private fields"
Private _title As String = String.Empty
Private _height As Unit = 20
Private _width As Unit = 75
Private _verticalAlign As VerticalAlign = VerticalAlign.NotSet
Private _horizontalAlign As HorizontalAlign = HorizontalAlign.NotSet
Private _tabBody As ITemplate
'Private _backColor As Color '背景色 20080805
#End Region
#Region "public properties"
'''' <summary>
'''' 背景色
'''' </summary>
'''' <value></value>
'''' <returns></returns>
'''' <remarks></remarks>
'Public Property BackColor() As Color
' Get
' Return _backColor
' End Get
' Set(ByVal value As Color)
' _backColor = value
' End Set
'End Property
''' <summary>
''' タイトル
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Title() As String
Get
Return _title
End Get
Set(ByVal value As String)
_title = 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>
''' 列幅
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Width() As Unit
Get
Return _width
End Get
Set(ByVal value As Unit)
_width = 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 TabBody() As ITemplate
Get
Return _tabBody
End Get
Set(ByVal value As ITemplate)
_tabBody = 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 AdvControls
<SecurityPermission(SecurityAction.Demand, UnmanagedCode:=True)> _
Class MyTabControlDesigner
Inherits CompositeControlDesigner
#Region "privates"
Private Const HEADER_PREFIX As String = "Header"
Private Const CONTENT_PREFIX As String = "Content"
Private tabControl As MyTabControl
#End Region
#Region "implementations"
Public Overloads Overrides Sub Initialize(ByVal component As IComponent)
' Initialize the base
MyBase.Initialize(component)
tabControl = CType(component, MyTabControl)
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 MyTabPage In tabControl.TabPages
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 + tabControl.CurrentDesignTab.ToString(), False)
regions.Add(editableRegion)
' Set the highlight for the selected region
regions(tabControl.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(tabControl.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 tabControl.TabPages.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) = (tabControl.TabPages.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) <> tabControl.CurrentDesignTab.ToString() Then
'extract the index of the design region, and set the CurrentDesignTab index
tabControl.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 TabPages
If (Not host Is Nothing) And (tabControl.TabPages.Count > 0) Then
'we need to get the contents of the TabBody of the tabControl
Dim template As ITemplate = tabControl.TabPages.Item(0).TabBody
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 = tabControl.TabPages.Item(tabIndex).TabBody
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
tabControl.TabPages.Item(tabIndex).TabBody = 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 AdvControls
<ParseChildren(True, "TabPages"), _
ToolboxData("<{0}:MyTabControl runat=""server"" Width=""125px"" Height=""100px""></{0}:MyTabControl>"), _
PersistChildren(False), _
Designer(GetType(MyTabControlDesigner))> _
Public Class MyTabControl
Inherits CompositeControl
#Region "private fields"
Private _tabPages As MyTabPageCollection
Private _currentDesignTab As Integer
Private _selectedTab As Integer
#End Region
#Region "public properties"
<PersistenceMode(PersistenceMode.InnerProperty), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible), _
MergableProperty(False)> _
Public ReadOnly Property TabPages() As MyTabPageCollection
Get
If _tabPages Is Nothing Then
_tabPages = New MyTabPageCollection()
End If
Return _tabPages
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
''' <summary>
''' Get or set the runtime active tab.
''' </summary>
Public Property SelectedTab() As Integer
Get
Return _selectedTab
End Get
Set(ByVal value As Integer)
_selectedTab = value
End Set
End Property
#End Region
#Region "private methods"
''' <summary>
''' BuildTitles:タイトルの内容を作成する
''' </summary>
''' <param name="tabControlTable"></param>
''' <remarks></remarks>
Private Sub BuildTitles(ByRef tabControlTable As Table)
'Create the titles row
Dim titlesRow As New TableRow()
titlesRow.HorizontalAlign = HorizontalAlign.Center
Dim intWidth As Integer = 0
Dim ii As Integer = 0
For Each tabPage As MyTabPage In _tabPages
'Create titles cells
Dim tabTitleCell As New TableCell
tabTitleCell.Text = tabPage.Title
'tabTitleCell.Width = New Unit("") '何
tabTitleCell.Height = tabPage.Height '何
tabTitleCell.Width = tabPage.Width '何
intWidth += tabPage.Width.Value
tabTitleCell.HorizontalAlign = tabPage.HorizontalAlign '何
tabTitleCell.VerticalAlign = tabPage.VerticalAlign '何
tabTitleCell.BorderStyle = WebControls.BorderStyle.Outset
tabTitleCell.BorderWidth = New Unit("1")
tabTitleCell.BorderColor = Color.Black '何
'tabTitleCell.Style("padding") = "1px 1px 1px 1px";
tabTitleCell.Style("cursor") = "hand"
tabTitleCell.Wrap = False
tabTitleCell.Height = New Unit("20")
'tabTitleCell.BackColor = Color.White '何
tabTitleCell.CssClass = "TabControl_Title_backcolor_False"
tabTitleCell.ForeColor = Color.Black '何
If Not DesignMode Then
'Highlight the selected tab title
If _selectedTab = ii Then
'tabTitleCell.Style("background-color") = ColorTranslator.ToHtml(Color.DarkGray)'何
'tabTitleCell.Attributes.Add("style", "background-color: #8cc1ff;cursor:hand;") '何 20080708
tabTitleCell.CssClass = "TabControl_Title_backcolor_True" '何 20080805
End If
End If
'タブのタイトル押下時のイベント属性を追加する
tabTitleCell.Attributes.Add("onclick", "ShowTab(this, " + ii.ToString() + ")")
titlesRow.Cells.Add(tabTitleCell)
ii += 1
Next
'Add additional empty cell
Dim tc1 As New TableCell()
'tc1.Width = New Unit("100%") '何
If intWidth <= tabControlTable.Width.Value Then
tc1.Width = New Unit(tabControlTable.Width.Value - intWidth) '何 20080709
tc1.CssClass = "TabControl_Title_backcolor_False"
Else
tabControlTable.Width = New Unit(intWidth)
End If
tc1.Height = New Unit("20")
'tc1.BorderWidth = new Unit("1")'何 20080707
'tc1.BorderColor = Color.Black'何 20080707
tc1.Attributes.Add("style", "border-bottom:solid 1px black;") '何 20080707
titlesRow.Cells.Add(tc1)
titlesRow.Height = New Unit("20")
'titlesRow.BackColor = Color.White '何
tabControlTable.Rows.Add(titlesRow)
End Sub
''' <summary>
''' テーブル中の行を作成する
''' </summary>
''' <param name="tabControlTable"></param>
''' <remarks></remarks>
Private Sub BuildContentRows(ByRef tabControlTable As Table)
'Create content row(s)
If DesignMode Then
Dim contentRow As New TableRow
Dim contentCell As TableCell = BuildContentCell(contentRow)
_tabPages.Item(_currentDesignTab).TabBody.InstantiateIn(contentCell)
tabControlTable.Rows.Add(contentRow)
Else
Dim counter As Integer = 0
For Each tabPage As MyTabPage In _tabPages
Dim contentRow As New TableRow
Dim contentCell As TableCell = BuildContentCell(contentRow)
If Not tabPage.TabBody Is Nothing Then
tabPage.TabBody.InstantiateIn(contentCell)
End If
'only the selected tab body should be visible
If _selectedTab = counter Then
contentRow.Style("display") = "block"
Else
contentRow.Style("display") = "none"
End If
contentRow.Cells.Add(contentCell)
tabControlTable.Rows.Add(contentRow)
counter += 1
Next
End If
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.ColumnSpan = _tabPages.Count + 1
'tc.BackColor = Color.White '何 20080805
tc.CssClass = "TabControl_Body_backcolor" '何 20080805
tc.BorderWidth = New Unit("1")
tc.BorderStyle = WebControls.BorderStyle.Ridge '何
'tc.BorderColor = Color.Silver'何
tc.BorderColor = Color.Black '何
'tc.Style("padding") = "1px 1px 1px 1px"
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)
If DesignMode Then
_tabPages.Item(_currentDesignTab).TabBody.InstantiateIn(Me)
End If
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 tabControlTable As New Table()
tabControlTable.CellSpacing = 0
tabControlTable.CellPadding = 0
tabControlTable.Attributes.Add("style", "border-bottom:solid 1px black;") '何 20080707
tabControlTable.BorderStyle = BorderStyle
tabControlTable.Width = Me.Width
tabControlTable.Height = Me.Height 'New Unit(Me.Height.Value - 37)
tabControlTable.BackColor = ColorTranslator.FromHtml("inactiveborder")
'keep a the selected tab index in a an attribute
tabControlTable.Attributes.Add("ActiveTabIdx", _selectedTab.ToString())
BuildTitles(tabControlTable)
BuildContentRows(tabControlTable)
'Add the finished tabControlTable to the Controls collection
Controls.Add(tabControlTable)
End Sub
#End Region
End Class
End Namespace