LoginDesigner.GetDesignTimeHtml(DesignerRegionCollection) Метод

Определение

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

public:
 override System::String ^ GetDesignTimeHtml(System::Web::UI::Design::DesignerRegionCollection ^ regions);
public override string GetDesignTimeHtml (System.Web.UI.Design.DesignerRegionCollection regions);
override this.GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
Public Overrides Function GetDesignTimeHtml (regions As DesignerRegionCollection) As String

Параметры

regions
DesignerRegionCollection

Объект DesignerRegionCollection, к которому добавляются определения областей с возможностью выбора и щелчка в представлении времени разработки для этого элемента управления.

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

String

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

Примеры

В следующем примере кода показано, как переопределить GetDesignTimeHtml метод в классе, наследуемом от LoginDesigner класса, чтобы изменить внешний вид элемента управления, производного от Login элемента управления во время разработки. Пример рисует синюю пунктирную границу вокруг элемента управления, чтобы сделать ее экстент более видимым, если 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. 
    MyLogin myLoginCtl = (MyLogin)ViewControl;
    string markup = null;

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

        // Set the design time properties and catch any exceptions.
        try
        {
            myLoginCtl.BorderStyle = BorderStyle.Dashed;
            myLoginCtl.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 myLoginCtl As MyLogin = CType(ViewControl, MyLogin)
    Dim markup As String = Nothing

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

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

        ' Set the design time properties and catch any exceptions.
        Try
            myLoginCtl.BorderStyle = BorderStyle.Dashed
            myLoginCtl.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

Комментарии

Метод GetDesignTimeHtml создает объект для LayoutTemplate свойства связанного Login элемента управления и добавляет его в DesignerRegionCollection объект, на который ссылается regions параметр.EditableDesignerRegion Этот GetDesignTimeHtml метод использует базовый GetDesignTimeHtml метод для создания разметки для отрисовки элемента управления во время разработки Login .

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

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

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

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