共用方式為


ListControlDesigner.GetDesignTimeHtml 方法

定義

取得在設計階段用來表示控制項的 HTML。

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

傳回

String,包含在設計階段用來呈現衍生自 ListControl 之控制項的標記。

範例

下列程式碼範例會 GetDesignTimeHtml 覆寫 方法,以自訂設計介面上相關聯控制項所顯示的標記。 BackColor如果未為相關聯的控制項定義 屬性,則會將其設定為 Gainsboro ,且控制項會以該背景色彩顯示。 完成此動作之後,會呼叫 方法的基底實作 GetDesignTimeHtml

此程式碼範例是提供給 類別之較大範例的 ListControlDesigner 一部分。

// Create the markup to display the control on the design surface. 
public override string GetDesignTimeHtml()
{
    string designTimeMarkup = null;

    // Create variables to access the control
    // item collection and back color.
    ListItemCollection items = simpleRadioButtonList.Items;
    Color oldBackColor = simpleRadioButtonList.BackColor;

    // Check the property values and render the markup
    // on the design surface accordingly.
    try
    {
        if (oldBackColor == Color.Empty)
            simpleRadioButtonList.BackColor = Color.Gainsboro;

        if (changedDataSource)
            items.Add("Updated to a new data source: " + 
                DataSource + ".");

        // Call the base method to generate the markup.
        designTimeMarkup = base.GetDesignTimeHtml();
    }
    catch (Exception ex)
    {
        // Catch any exceptions that occur.
        designTimeMarkup = GetErrorDesignTimeHtml(ex);
    }
    finally
    {
        // Set the properties back to their original state.
        simpleRadioButtonList.BackColor = oldBackColor;
        items.Clear();
    }

    return designTimeMarkup;
} // GetDesignTimeHtml
' Create the markup to display the control on the design surface.
Public Overrides Function GetDesignTimeHtml() As String

    Dim designTimeHtml As String = String.Empty

    ' Create variables to access the control's
    ' item collection and back color. 
    Dim items As ListItemCollection = simpleRadioButtonList.Items
    Dim oldBackColor As Color = simpleRadioButtonList.BackColor

    ' Check the property values and render the markup
    ' on the design surface accordingly.
    Try
        If (Color.op_Equality(oldBackColor, Color.Empty)) Then
            simpleRadioButtonList.BackColor = Color.Gainsboro
        End If

        If (changedDataSource) Then
            items.Add( _
                "Updated to a new data source: " & DataSource & ".")
        End If

        designTimeHtml = MyBase.GetDesignTimeHtml()

    Catch ex As Exception
        ' Catch any exceptions that occur.
        MyBase.GetErrorDesignTimeHtml(ex)

    Finally
        ' Set the properties back to their original state.
        simpleRadioButtonList.BackColor = oldBackColor
        items.Clear()
    End Try

    Return designTimeHtml
End Function ' GetDesignTimeHtml

備註

如果衍生自 ListControl 物件的相關聯控制項是資料系結, GetDesignTimeHtml 方法會 Items 清除集合,並加入 String 訊息,指出控制項是資料系結。 如果關聯的控制項不是資料系結,而且集合是空的 Items ,則 GetDesignTimeHtml 會新增一則 String 訊息,指出控制項未系結。 然後,會 GetDesignTimeHtml 呼叫其基底方法來產生標記。

適用於

另請參閱