Share via


DataGridDesigner.GetDesignTimeHtml 方法

定义

获取设计时用于表示 DataGrid 控件的 HTML 标记。

public:
 override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public 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

适用于

另请参阅