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

📄 wroxbuttondesigner.vb

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

Namespace WroxDesignVB.Design

    Public Class WroxButtonDesigner : Inherits ControlDesigner

        Public Sub New()
        End Sub


        Public Overrides Function GetDesignTimeHtml() As String
            Try
                Dim wb As WroxButton = CType(MyBase.Component, WroxButton)

                If (wb.Text = String.Empty And _
                 wb.ImageUrl = String.Empty) Then Return GetEmptyDesignTimeHtml()

                Dim pnl As Panel = New Panel()
                pnl.CopyBaseAttributes(wb)
                pnl.Controls.Add(wb)
                pnl.BorderStyle = BorderStyle.Dotted
                pnl.BorderWidth = New Unit(2, UnitType.Point)
                pnl.Height = New Unit(pnl.Height.Value + 4)
                pnl.Width = New Unit(pnl.Width.Value + 4)
                'Simulate an exception being thrown
                'throw new InvalidOperationException
                '	("My custom exception test.")

                Return GetRenderHtml(pnl)
            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 set the Text or ImageUrl to initialize the button."
            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

        '/ <summary>
        '/ Renders a control to an in-memory string and returns the result.
        '/ </summary>
        '/ <param name="control">The control to render.</param>
        '/ <returns>The HTML representing the rendered control.</returns>
        Private Function GetRenderHtml(ByVal control As Control) As String
            Dim text As StringWriter = New StringWriter()
            Dim writer As HtmlTextWriter = New HtmlTextWriter(text)
            Control.RenderControl(writer)
            Return text.ToString()
        End Function

    End Class
End Namespace


⌨️ 快捷键说明

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