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,可在其中加入控制項設計階段檢視之可選取和可點選區域的定義。

傳回

字串,包含在設計階段用來呈現 Login 的標記。

範例

下列程式碼範例示範如何覆寫 GetDesignTimeHtml 繼承自 LoginDesigner 類別的 類別中的 方法,以變更在設計階段衍生自 Login 控制項的控制面板。 如果 BorderStyle 控制項的 屬性是 NotSetNone 值,本範例會在控制項周圍繪製藍色虛線框線,使其範圍更可見。

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

備註

方法 GetDesignTimeHtmlEditableDesignerRegionLayoutTemplate 相關聯 Login 控制項的 屬性建立 物件,並將它新增至 DesignerRegionCollection 參數所 regions 參考的物件。 方法 GetDesignTimeHtmlGetDesignTimeHtml 使用基底方法來產生控制項設計階段轉譯的 Login 標記。

給繼承者的注意事項

如果您覆寫 GetDesignTimeHtml(DesignerRegionCollection) 方法,請務必呼叫 GetDesignTimeHtml() 基底方法,因為它最終會透過數個覆寫層級、在控制項上 Login 呼叫 或 控制項的複本來產生標記。

適用於

另請參閱