LabelDesigner Class

Provides design-time support in a visual designer for the Label Web server control.

Namespace: System.Web.UI.Design.WebControls
Assembly: System.Design (in system.design.dll)

'Declaration
Public Class LabelDesigner
	Inherits TextControlDesigner
'Usage
Dim instance As LabelDesigner

public class LabelDesigner extends TextControlDesigner
public class LabelDesigner extends TextControlDesigner

The Label control allows text to be displayed programmatically on a Web page.

In a visual designer, when you switch from Source to Design view, the markup source code that describes a Label control is parsed and a design-time version of the control is created on the design surface. When you switch back to Source view, the design-time control is persisted to the markup source code and edited into the markup for the Web page. The LabelDesigner class provides design-time support for the Label control.

The OnComponentChanged method is called when there is a change to the associated Label control.

The following code example shows how to derive the SampleLabel control from the Label control, and applies a DesignerAttribute attribute on the SampleLabel control to associate it with the SampleLabelDesigner class.

The code example also derives the SampleLabelDesigner from the LabelDesigner class. It overrides the GetDesignTimeHtml method to set the BorderStyle property to Dashed, if the original BorderStyle was the NotSet or None value. This improves the visibility of the associated control at design time.

Imports System
Imports System.Web
Imports System.ComponentModel
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design.WebControls
Imports System.Security.Permissions

Namespace Examples.VB.WebControls.Design

    ' The SampleLabel is a copy of the Label.
    <AspNetHostingPermission(SecurityAction.Demand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <AspNetHostingPermission(SecurityAction.InheritanceDemand, _
        Level:=AspNetHostingPermissionLevel.Minimal)> _
    <Designer(GetType(Examples.VB.WebControls.Design.SampleLabelDesigner))> _
    Public Class SampleLabel
        Inherits Label
    End Class ' SampleLabel

    ' Override members of the LabelDesigner.
    Public Class SampleLabelDesigner
        Inherits LabelDesigner

        ' Generate the design-time markup.
        Public Overrides Function GetDesignTimeHtml() As String

            ' Make the control more visible in the designer.  If the border 
            ' style is None or NotSet, change the border to a dashed line. 
            Dim sampleLabel As SampleLabel = CType(Component, SampleLabel)
            Dim designTimeMarkup As String = Nothing

            ' Check if the border style should be changed.
            If (sampleLabel.BorderStyle = BorderStyle.NotSet Or _
                sampleLabel.BorderStyle = BorderStyle.None) Then

                Dim oldBorderStyle As BorderStyle = sampleLabel.BorderStyle

                Try
                    ' Set the design-time BorderStyle.
                    sampleLabel.BorderStyle = BorderStyle.Dashed

                    ' Call the base method to generate the markup.
                    designTimeMarkup = MyBase.GetDesignTimeHtml()

                Catch ex As Exception
                    ' If an exception occurs, generate an error message.
                    designTimeMarkup = GetErrorDesignTimeHtml(ex)

                Finally
                    ' Restore the BorderStyle to its original setting.
                    sampleLabel.BorderStyle = oldBorderStyle
                End Try

            Else
                ' Call the base method to generate the markup.
                designTimeMarkup = MyBase.GetDesignTimeHtml()
            End If

            Return designTimeMarkup
        End Function ' GetDesignTimeHtml
    End Class ' SampleLabelDesigner
End Namespace ' Examples.VB.WebControls.Design

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: