DataGridDesigner.GetDesignTimeHtml 方法      
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取设计时用于表示 DataGrid 控件的 HTML 标记。
public:
 override System::String ^ GetDesignTimeHtml();public override string GetDesignTimeHtml ();override this.GetDesignTimeHtml : unit -> stringPublic Overrides Function GetDesignTimeHtml () As String返回
设计时用于表示 DataGrid 控件的 HTML 标记。
示例
下面的代码示例演示如何重写 GetDesignTimeHtml 方法以更改控件在设计图面上的外观 DataGrid 。
代码使用 Try...Catch...Finally 语法执行以下操作:
- 节 - Try更改数据网格控件的属性值。
- 节 - Catch捕获任何异常并将其发送到 GetErrorDesignTimeHtml 方法。
- 节 - Finally将属性设置为其原始值。
此示例是为 类提供的更大示例的 DataGridDesigner 一部分。
' Override the GetDesignTimeHtml method to add style to the control
' on the design surface.
Public Overrides Function GetDesignTimeHtml() As String
    ' Cast the control to the Component property of the designer.
    simpleList = CType(Component, SimpleDataList)
    Dim designTimeHtml As String = Nothing
    ' Create variables to hold current property values.
    Dim oldBorderWidth As Unit = simpleList.BorderWidth
    Dim oldBorderColor As Color = simpleList.BorderColor
    ' Set the properties and generate the design-time HTML.
    If (simpleList.Enabled) Then
        Try
            simpleList.BorderWidth = Unit.Point(5)
            simpleList.BorderColor = Color.Purple
            designTimeHtml = MyBase.GetDesignTimeHtml()
            ' Call the GetErrorDesignTimeHtml method if an
            ' exception occurs.
        Catch ex As Exception
            designTimeHtml = GetErrorDesignTimeHtml(ex)
            ' Return the properties to their original settings.
        Finally
            simpleList.BorderWidth = oldBorderWidth
            simpleList.BorderColor = oldBorderColor
        End Try
        ' If the list is not enabled, call the GetEmptyDesignTimeHtml
        ' method.
    Else
        designTimeHtml = GetEmptyDesignTimeHtml()
    End If
    Return designTimeHtml
End Function