⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webcontrolsizeconverter.vb

📁 ASP.NET服务器控件高级编程电子书
💻 VB
字号:
Imports System
Imports System.ComponentModel
Imports System.Globalization
Imports System.Web.UI.WebControls

Namespace WroxDesignVB.Design

    Public Class WebControlSizeConverter : Inherits TypeConverter


        Public Sub New()
        End Sub

        Private Function FromString(ByVal value As Object) As WebControlSize
            Dim values As String() = CType(value, String).Split(Char.Parse(","))

            If (values.Length <> 2) Then Throw New ArgumentException("Could not convert the value")

            Try
                Dim h As Unit = New Unit(values(0))
                Dim w As Unit = New Unit(values(1))
                Return New WebControlSize(h, w)
            Catch
                Throw New ArgumentException("Could not convert the value")
            End Try
        End Function


        Private Overloads Function ToString(ByVal value As Object) As String
            Dim size As WebControlSize = CType(value, WebControlSize)
            Return String.Format("0, 1", size.Height, size.Width)
        End Function

        Public Overloads Overrides Function CanConvertFrom(ByVal context As ITypeDescriptorContext, _
                        ByVal sourceType As Type) As Boolean
            If (TypeOf (sourceType) Is String) Then Return True
            Return MyBase.CanConvertFrom(context, sourceType)
        End Function

        Public Overloads Overrides Function ConvertFrom(ByVal context As ITypeDescriptorContext, _
        ByVal culture As CultureInfo, ByVal value As Object) As Object

            If (value Is GetType(String)) Then Return FromString(value)
            Return MyBase.ConvertFrom(context, culture, value)
        End Function

        Public Overloads Overrides Function CanConvertTo(ByVal context As ITypeDescriptorContext, _
        ByVal destinationType As Type) As Boolean

            If (destinationType Is GetType(String)) Then Return True
            Return MyBase.CanConvertTo(context, destinationType)
        End Function

        Public Overloads Overrides Function ConvertTo(ByVal context As ITypeDescriptorContext, _
        ByVal culture As CultureInfo, ByVal value As Object, _
        ByVal destinationType As Type) As Object

            If (destinationType Is GetType(String)) Then
                Dim comp As IComponent
                For Each comp In context.Container.Components
                    If (TypeOf (comp) Is Label) Then
                        CType(comp, Label).Text = "WebControlSize Changed!!"
                        Return ToString(value)
                    End If
                Next
            End If
            Return MyBase.ConvertTo(context, culture, value, destinationType)
        End Function

    End Class
End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -