TableDesigner.GetDesignTimeHtml Método
Definição
Obtém o HTML usado para representar o controle em tempo de design.Gets the HTML that is used to represent the control at design time.
public:
override System::String ^ GetDesignTimeHtml();
public override string GetDesignTimeHtml ();
override this.GetDesignTimeHtml : unit -> string
Public Overrides Function GetDesignTimeHtml () As String
Retornos
O HTML usado para representar o controle em tempo de design.The HTML used to represent the control at design time.
Exemplos
O exemplo de código a seguir demonstra como substituir o GetDesignTimeHtml método para exibir linhas e células para a StyledTable classe na superfície de design.The following code example demonstrates how to override the GetDesignTimeHtml method to display rows and cells for the StyledTable class on the design surface. No Try bloco, o código verifica se a tabela contém linhas ou células e, se não tiver, cria uma linha e executa um loop para criar duas células para a linha, juntamente com o texto do espaço reservado para exibir em cada célula no tempo de design.In the Try block, the code checks whether the table contains any rows or cells, and if it does not, creates a row and performs a loop to create two cells for the row, along with placeholder text to display in each cell at design time. Se a tabela não estiver vazia, mas uma linha for, o código executará o mesmo loop para criar e preencher as células.If the table is not empty, but a row is, the code performs the same loop to create and populate the cells. No Finally bloco, o código retorna os valores para seu estado original.In the Finally block, the code returns the values to their original state.
' 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
Comentários
O GetDesignTimeHtml método garante que a tabela tenha pelo menos uma linha e célula e que as células contenham algum texto para exibição em tempo de design.The GetDesignTimeHtml method ensures that the table has at least one row and cell and that the cells contain some text for display at design time.