ListControlDesigner.GetDesignTimeHtml 方法

定义

获取用于在设计时表示控件的 HTML。

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

返回

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 对象派生的关联控件是数据绑定的,该方法 GetDesignTimeHtmlItems 清除集合,并添加一条消息 String ,指示控件是数据绑定的。 如果关联的控件未绑定数据且 Items 集合为空,则 GetDesignTimeHtml 添加一条消息 String ,指示控件未绑定。 然后,调用 GetDesignTimeHtml 其基方法以生成标记。

适用于

另请参阅