*控件*有滚动条的LISTBOX

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值