共用方式為


TableDesigner.GetDesignTimeHtml 方法

定義

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

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

傳回

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

範例

下列程式碼範例示範如何覆寫 方法, GetDesignTimeHtml 以在設計介面上顯示類別的資料列和儲存格 StyledTable 。 在 Try 區塊中,程式碼會檢查資料表是否包含任何資料列或儲存格,如果不包含,則會建立一個資料列,並執行迴圈來建立資料列的兩個儲存格,以及在設計階段在每個儲存格中顯示的預留位置文字。 如果資料表不是空的,但資料列是 ,程式碼會執行相同的迴圈來建立和填入資料格。 在 Finally 區塊中,程式碼會將值傳回至其原始狀態。

' Override the GetDesignTimeHtml method to display
' placeholder text at design time for the 
' rows and cells of the StyledTable class.
Public Overrides Function GetDesignTimeHtml() As String
    Dim sTable As StyledTable = CType(Component, StyledTable)
    Dim designTimeHTML As String
    Dim rows As TableRowCollection = sTable.Rows
    Dim cellsWithDummyContents As ArrayList = Nothing
   
    Dim emptyTable As Boolean = rows.Count = 0
    Dim emptyRows As Boolean = False
    Dim counter As Integer = 1
    Dim numcells As Integer = 2
    
    Try     
        ' Create two cells to display
        ' in a row at design time.
        If emptyTable Then
            Dim row As TableRow = New TableRow()
            rows.Add(row)
      
            Dim i As Integer
            For i = 0 To numcells - 1
                Dim c As TableCell = New TableCell()
                c.Text = "Cell #" & counter.ToString()
                counter += 1
                rows(0).Cells.Add(c)
            Next i
        Else
            emptyRows = True
            Dim j As Integer
            For j = 0 To rows.Count - 1
                If rows(j).Cells.Count <> 0 Then
                    emptyRows = False
                    Exit For
                End If
            Next j
            If emptyRows = True Then
                Dim k As Integer
                For k = 0 To numcells - 1
                    Dim c As TableCell = New TableCell()
                    c.Text = "Cell #" & counter.ToString()
                    counter += 1
                    rows(0).Cells.Add(c)
                Next k
             End If
        End If
   
        If emptyTable = False Then
            ' If the rows and cells were defined by the user, but the
            ' cells remain empty this code defines a string to display 
            ' in them at design time.
            Dim row As TableRow
            For Each row In rows
                Dim c As TableCell
                For Each c In row.Cells
                    If ((c.Text.Length = 0) AndAlso (c.HasControls() = False)) Then
                       If cellsWithDummyContents Is Nothing Then
                           cellsWithDummyContents = New ArrayList()
                       End If
                       cellsWithDummyContents.Add(c)
                       c.Text = "Cell #" & counter.ToString()
                       counter += 1
                    End If
                Next c
            Next row
        End If
        ' Retrieve the design-time HTML for the StyledTable class.
        designTimeHTML = MyBase.GetDesignTimeHtml()

    Finally
        ' If the StyledTable was empty before the dummy text was added,
        ' restore it to that state.
        If emptyTable Then
            rows.Clear()
        Else
            ' Clear the cells that were empty before the dummy text 
            ' was added.
            If Not (cellsWithDummyContents Is Nothing) Then
                Dim c As TableCell
                For Each c In  cellsWithDummyContents
                    c.Text = [String].Empty
                Next c
            End If
            If emptyRows Then
                rows(0).Cells.Clear()
            End If
        End If
   
    End Try
    Return designTimeHTML
End Function

備註

方法 GetDesignTimeHtml 可確保資料表至少有一個資料列和儲存格,而且儲存格包含一些文字以供設計階段顯示。

適用於

另請參閱