Поделиться через


LoginStatusDesigner.GetDesignTimeHtml Метод

Определение

Получает разметку, используемую для отрисовки связанного элемента управления во время разработки.

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

Возвращаемое значение

Строка, содержащая разметку, которая используется для отрисовки объекта LoginStatus во время разработки.

Примеры

В следующем примере кода показано, как переопределить GetDesignTimeHtml метод в классе, наследуемом от LoginStatusDesigner класса , чтобы изменить внешний вид элемента управления, производного от класса во время разработки LoginStatus . В примере рисуется синяя пунктирная граница вокруг элемента управления, чтобы сделать его экстент более видимым, если BorderStyle свойство элемента управления имеет NotSet значение или None .

// 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

Комментарии

LogoutText Если свойство или LoginText (в зависимости от того, вошел ли пользователь в систему), имеет значение null, пустая строка ("") или один пробел (" "), GetDesignTimeHtml метод присваивает свойству LogoutText или LoginText соответствующим образом свойство , заключенное ID в квадратные скобки ("[ ]"). Затем, независимо от параметра или LogoutText, метод вызывает базовый GetDesignTimeHtml метод для создания разметки для отрисовки LoginText элемента управления во время разработки LoginStatusGetDesignTimeHtml.

Примечания для тех, кто наследует этот метод

При переопределении GetDesignTimeHtml() метода обязательно вызовите GetDesignTimeHtml() базовый метод, так как он в конечном итоге через несколько уровней переопределения вызывает LoginStatus элемент управления или копию элемента управления для создания разметки.

Применяется к

См. также раздел