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

📄 wroxtoolbardesigner.vb

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

Namespace WroxDesignVB.Design

    Public Class WroxToolBarDesigner : Inherits ControlDesigner

        Public Overrides ReadOnly Property Verbs() As DesignerVerbCollection
            Get
                Dim col As DesignerVerb() = New DesignerVerb() { _
                 New DesignerVerb("Wrox Format...", New EventHandler(AddressOf OnWroxFormat)), _
                 New DesignerVerb("Edit Buttons...", New EventHandler(AddressOf OnEditButtons))}
                Return New DesignerVerbCollection(col)
            End Get
        End Property


        Public Sub OnWroxFormat(ByVal sender As Object, ByVal e As EventArgs)
            Dim wb As WroxToolBar = CType(Component, WroxToolBar)
            'Apply a formatting style.
            wb.BackColor = Color.LightSkyBlue
            wb.BorderColor = Color.Black
            wb.Font.Name = "Tahoma"
            wb.Font.Size = New FontUnit("8pt")
            wb.ForeColor = Color.White
            wb.BorderStyle = BorderStyle.Solid
            wb.BorderWidth = New Unit(1, UnitType.Point)
            'Notify the environment we have changed the component.
            RaiseComponentChanged(Nothing, Nothing, Nothing)
            UpdateDesignTimeHtml()
        End Sub

        Public Sub OnEditButtons(ByVal sender As Object, ByVal e As EventArgs)
            Dim wb As WroxToolBar = CType(Component, WroxToolBar)
            Dim form As WroxToolBarButtonsForm = New WroxToolBarButtonsForm(wb.Buttons)

            If (form.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
                wb.Buttons = form.Buttons
                RaiseComponentChanged(Nothing, Nothing, Nothing)
                UpdateDesignTimeHtml()
            End If
        End Sub

        Private Sub TransferAttributes(ByVal source As WebControl, ByVal destination As WebControl)
            destination.CopyBaseAttributes(source)
            destination.Style.Remove("POSITION")
            destination.Style.Remove("LEFT")
            destination.Style.Remove("TOP")
            destination.Font.CopyFrom(source.Font)
            destination.BackColor = source.BackColor
            destination.BorderColor = source.BorderColor
            destination.ForeColor = source.ForeColor
        End Sub


        Public Overrides Function GetPersistInnerHtml() As String

            Dim text As StringWriter = New StringWriter()
            Dim writer As HtmlTextWriter = New HtmlTextWriter(text)

            Dim tbr As WroxToolBar = CType(Component, WroxToolBar)

            writer.WriteFullBeginTag("buttons")
            Dim btn As WroxButton
            For Each btn In tbr.Buttons
                'We won't persist other attributes, which will be copied 
                'from the toolbar settings.
                writer.WriteBeginTag("button")
                writer.WriteAttribute("ID", btn.ID)
                writer.WriteAttribute("Text", btn.Text)
                writer.WriteAttribute("ImageUrl", btn.ImageUrl)
                writer.Write(" />")
            Next

            writer.WriteEndTag("buttons")
            Return text.ToString()
        End Function

        Public Overrides Function GetDesignTimeHtml() As String
            Try
                Dim wb As WroxToolBar = CType(MyBase.Component, WroxToolBar)
                If (wb.Buttons.Count = 0) Then _
                    Return GetEmptyDesignTimeHtml()
                'Returns just the same runtime layout.
                Return MyBase.GetDesignTimeHtml()
            Catch e As Exception
                Return GetErrorDesignTimeHtml(e)
            End Try
        End Function

        Protected Overrides Function GetEmptyDesignTimeHtml() As String
            'Render design time warning if there's nothing to display.
            Dim text As String = "Please add WroxButtons to the toolbar."
            Return CreatePlaceHolderDesignTimeHtml(text)
        End Function

        Protected Overrides Function GetErrorDesignTimeHtml(ByVal e As Exception) As String
            Dim text As String = String.Format("0123", _
             "There was an error and the control can't be displayed.", _
             "<BR>", "Exception: inherits ", e.Message)

            Return CreatePlaceHolderDesignTimeHtml(text)
        End Function

    End Class
End Namespace

⌨️ 快捷键说明

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