Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web
Imports System.Drawing.Design
Imports System.Text.RegularExpressions
<DefaultProperty("Text"), ToolboxData("<{0}:XScrollListBox runat=server></{0}:XScrollListBox>")> _
Public Class XScrollListBox
Inherits System.Web.UI.WebControls.WebControl
Private WithEvents conFromListBox As ListBox
Public Enum ScrollBar
none
All
X
Y
End Enum
#Region "プロパティ"
#Region "親クラスから継承された表示プロパティ"
'コントロールのID用
Public Overrides Property ID() As String
Get
Dim mID As String
mID = IIf(viewstate("mID") Is Nothing, MyBase.ID, viewstate("mID"))
conFromListBox.ID = mID & "_SubFromListBox"
Return mID
End Get
Set(ByVal Value As String)
viewstate("mID") = Value
End Set
End Property
'CssClass
<NotifyParentProperty(True)> _
Public Overrides Property CssClass() As String
Get
Return MyBase.CssClass
End Get
Set(ByVal Value As String)
MyBase.CssClass = Value
If Not conFromListBox Is Nothing Then
conFromListBox.CssClass = MyBase.CssClass
End If
End Set
End Property
'BackColor
<NotifyParentProperty(True)> _
Public Overrides Property BackColor() As System.Drawing.Color
Get
Return MyBase.BackColor
End Get
Set(ByVal Value As System.Drawing.Color)
MyBase.BackColor = Value
If Not conFromListBox Is Nothing Then
conFromListBox.BackColor = MyBase.BackColor
End If
End Set
End Property
'ForeColor
<NotifyParentProperty(True)> _
Public Overrides Property ForeColor() As System.Drawing.Color
Get
Return MyBase.ForeColor
End Get
Set(ByVal Value As System.Drawing.Color)
MyBase.ForeColor = Value
If Not conFromListBox Is Nothing Then
conFromListBox.ForeColor = MyBase.ForeColor
End If
End Set
End Property
'Controlsプロパティ
Public Overrides ReadOnly Property Controls() As System.Web.UI.ControlCollection
Get
EnsureChildControls()
Return MyBase.Controls
End Get
End Property
#End Region
<NotifyParentProperty(True), _
Category("ChildControl"), Description("listbox")> _
Public ReadOnly Property SubFromListBox() As ListBox
Get
Me.EnsureChildControls()
Return conFromListBox
End Get
End Property
<NotifyParentProperty(True), _
Category("ChildControl"), Description("scrollType")> _
Public Property ScrollType() As ScrollBar
Get
Me.EnsureChildControls()
Return viewstate("scroll")
End Get
Set(ByVal Value As ScrollBar)
viewstate("scroll") = Value
End Set
End Property
<Category("Behavior"), DefaultValue("150px"), _
Description("scrollWidth")> _
Public Property ScrollBarWidth() As Unit
Get
Return IIf(viewstate("mScrollBarWidth") Is Nothing, "", viewstate("mScrollBarWidth"))
End Get
Set(ByVal Value As Unit)
viewstate("mScrollBarWidth") = Value
If Not Me.conFromListBox Is Nothing Then
Me.conFromListBox.Width = Value
End If
End Set
End Property
<Category("Behavior"), DefaultValue("150px"), _
Description("scrollHeight")> _
Public Property ScrollBarHeight() As Unit
Get
Return IIf(viewstate("mScrollBarHeight") Is Nothing, "", viewstate("mScrollBarHeight"))
End Get
Set(ByVal Value As Unit)
viewstate("mScrollBarHeight") = Value
If Not Me.conFromListBox Is Nothing Then
Me.conFromListBox.Height = Value
End If
End Set
End Property
#End Region
Public Sub New()
Me.ScrollBarWidth = Unit.Pixel(150)
Me.ScrollBarHeight = Unit.Pixel(150)
End Sub
Private Function IsDesignMode() As Boolean
If (HttpContext.Current Is Nothing) Then
Return True
Else
Return False
End If
End Function
Protected Overrides Sub CreateChildControls()
If conFromListBox Is Nothing Then
conFromListBox = New ListBox
conFromListBox.Height = Unit.Pixel(150)
conFromListBox.Width = Unit.Pixel(150)
End If
Call SetChildLayout()
End Sub
Private Sub SetChildLayout()
Dim htmlTable As Table
Dim htmlTableRow As TableRow
Dim divPanel As Panel
htmlTable = New Table
htmlTable.BorderWidth = Unit.Pixel(0)
htmlTable.CellSpacing = 0
htmlTable.CellPadding = 0
htmlTableRow = New TableRow
htmlTableRow.Cells.Add(New TableCell)
htmlTableRow.Cells(0).ColumnSpan = 4
htmlTableRow.Cells(0).HorizontalAlign = HorizontalAlign.Left
divPanel = New Panel
divPanel.ID = Me.ID & "_TopDiv"
Select Case Me.ScrollType
Case ScrollBar.All
divPanel.Style.Add("overflow", "Scroll")
Case ScrollBar.X
divPanel.Style.Add("overflow-x", "Scroll")
Case ScrollBar.Y
divPanel.Style.Add("overflow-y", "Scroll")
End Select
divPanel.Width = Me.ScrollBarWidth
divPanel.Height = Me.ScrollBarHeight
Me.conFromListBox.Width = Me.ScrollBarWidth
Me.conFromListBox.Height = Me.ScrollBarHeight
divPanel.Controls.Add(conFromListBox)
htmlTableRow.Cells(0).Controls.Add(divPanel)
htmlTable.Rows.Add(htmlTableRow)
MyBase.Controls.Add(htmlTable)
End Sub
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Me.EnsureChildControls()
If IsDesignMode() Then
MyBase.Controls.Clear()
Call SetChildLayout()
End If
MyBase.Render(writer)
End Sub
Protected Overrides Sub AddParsedSubObject(ByVal obj As Object)
If TypeOf (obj) Is ListBox Then
Me.conFromListBox = obj
End If
End Sub
Private Sub conFromListBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles conFromListBox.SelectedIndexChanged
RaiseBubbleEvent(sender, e)
End Sub
End Class
咹