Editare

Partajați prin


LoginStatusDesigner.GetDesignTimeHtml Method

Definition

Gets the markup that is used to render the associated control at design time.

public:
 override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String

Returns

A string containing the markup used to render the LoginStatus at design time.

Examples

The following code example shows how to override the GetDesignTimeHtml method in a class that is inherited from the LoginStatusDesigner class to change the appearance of a control that is derived from the LoginStatus class at design time. The example draws a blue, dashed border around the control to make its extent more visible, if the BorderStyle property of the control is the NotSet or None value.

// Generate the design-time markup.
public override string GetDesignTimeHtml()
{
    // Make the control more visible in the designer.  If the border 
    // style is None or NotSet, change the border to a blue dashed line. 
    MyLoginStatus myLoginStatusCtl = (MyLoginStatus)ViewControl;
    string markup = null;

    // Check if the border style should be changed.
    if (myLoginStatusCtl.BorderStyle == BorderStyle.NotSet ||
        myLoginStatusCtl.BorderStyle == BorderStyle.None)
    {
        BorderStyle oldBorderStyle = myLoginStatusCtl.BorderStyle;
        Color oldBorderColor = myLoginStatusCtl.BorderColor;

        // Set the design time properties and catch any exceptions.
        try
        {
            myLoginStatusCtl.BorderStyle = BorderStyle.Dashed;
            myLoginStatusCtl.BorderColor = Color.Blue;

            // Call the base method to generate the markup.
            markup = base.GetDesignTimeHtml();
        }
        catch (Exception ex)
        {
            markup = GetErrorDesignTimeHtml(ex);
        }
        finally
        {
            // It is not necessary to restore the border properties 
            // to their original values because the ViewControl 
            // was used to reference the associated control and the 
            // UsePreviewControl was not overridden.  

            // myLoginCtl.BorderStyle = oldBorderStyle;
            // myLoginCtl.BorderColor = oldBorderColor;
        }
    }
    else
    {
        // Call the base method to generate the markup.
        markup = base.GetDesignTimeHtml();
    }

    return markup;
} // GetDesignTimeHtml
' 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 blue dashed line. 
    Dim myLoginStatusCtl As MyLoginStatus = _
        CType(ViewControl, MyLoginStatus)
    Dim markup As String = Nothing

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

        Dim oldBorderStyle As BorderStyle = myLoginStatusCtl.BorderStyle
        Dim oldBorderColor As Color = myLoginStatusCtl.BorderColor

        ' Set the design time properties and catch any exceptions.
        Try
            myLoginStatusCtl.BorderStyle = BorderStyle.Dashed
            myLoginStatusCtl.BorderColor = Color.Blue

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

        Catch ex As Exception
            markup = GetErrorDesignTimeHtml(ex)

        Finally
            ' It is not necessary to restore the border properties 
            ' to their original values because the ViewControl 
            ' was used to reference the associated control and the 
            ' UsePreviewControl was not overridden.  

            ' myLoginCtl.BorderStyle = oldBorderStyle
            ' myLoginCtl.BorderColor = oldBorderColor
        End Try

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

    Return markup

End Function ' GetDesignTimeHtml

Remarks

If the LogoutText or LoginText property (depending on whether the user is logged in), is null, an empty string (""), or a single space (" "), the GetDesignTimeHtml method sets the LogoutText or LoginText property, as appropriate, to the ID property, enclosed in brackets ("[ ]"). Then, regardless of the setting of the LoginText or LogoutText, the GetDesignTimeHtml method calls the GetDesignTimeHtml base method to generate the markup for the design-time rendering of the LoginStatus control.

Notes to Inheritors

If you override the GetDesignTimeHtml() method, be sure to call the GetDesignTimeHtml() base method because it eventually, through several override levels, calls on the LoginStatus control or a copy of the control to generate the markup.

Applies to

See also