ControlDesigner.GetDesignTimeHtml Método

Definição

Recupera a marcação HTML que é usada para representar o controlo no momento do design.

Sobrecargas

Name Description
GetDesignTimeHtml(DesignerRegionCollection)

Recupera a marcação HTML para mostrar o controlo e preenche a coleção com as regiões atuais do designer de controlo.

GetDesignTimeHtml()

Recupera a marcação HTML que é usada para representar o controlo no momento do design.

GetDesignTimeHtml(DesignerRegionCollection)

Recupera a marcação HTML para mostrar o controlo e preenche a coleção com as regiões atuais do designer de controlo.

public:
 virtual System::String ^ GetDesignTimeHtml(System::Web::UI::Design::DesignerRegionCollection ^ regions);
public virtual string GetDesignTimeHtml(System.Web.UI.Design.DesignerRegionCollection regions);
abstract member GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
override this.GetDesignTimeHtml : System.Web.UI.Design.DesignerRegionCollection -> string
Public Overridable Function GetDesignTimeHtml (regions As DesignerRegionCollection) As String

Parâmetros

regions
DesignerRegionCollection

Uma coleção de regiões de design de controlo para o controlo associado.

Devoluções

A marcação HTML em tempo de design para o controlo associado, incluindo todas as regiões do designer de controlo.

Exemplos

O exemplo de código seguinte mostra como criar marcação HTML usando a DesignerRegionCollection coleção.

// Create the regions and design-time markup. Called by the designer host.
public override String GetDesignTimeHtml(DesignerRegionCollection regions) {
    // Create 3 regions: 2 clickable headers and an editable row
    regions.Add(new DesignerRegion(this, "Header0"));
    regions.Add(new DesignerRegion(this, "Header1"));

    // Create an editable region and add it to the regions
    EditableDesignerRegion editableRegion = 
        new EditableDesignerRegion(this, 
            "Content" + myControl.CurrentView, false);
    regions.Add(editableRegion);

    // Set the highlight for the selected region
    regions[myControl.CurrentView].Highlight = true;

    // Use the base class to render the markup
    return base.GetDesignTimeHtml();
}
' Create the regions and design-time markup. Called by the designer host.
Public Overrides Function GetDesignTimeHtml(ByVal regions As DesignerRegionCollection) As String
    ' Create 3 regions: 2 clickable headers and an editable row
    regions.Add(New DesignerRegion(Me, "Header0"))
    regions.Add(New DesignerRegion(Me, "Header1"))

    ' Create an editable region and add it to the regions
    Dim editableRegion As EditableDesignerRegion = _
        New EditableDesignerRegion(Me, _
            "Content" & myControl.CurrentView, False)
    regions.Add(editableRegion)

    ' Set the highlight for the selected region
    regions(myControl.CurrentView).Highlight = True

    ' Use the base class to render the markup
    Return MyBase.GetDesignTimeHtml()
End Function

Observações

O anfitrião de design chama o GetDesignTimeHtml método para obter a marcação HTML em tempo de design e a lista atual de regiões do designer de controlo. Usando a DesignerRegionCollection, o anfitrião de design pode então solicitar a marcação para cada região de design de controlo editável.

O GetDesignTimeHtml método é fornecido para um designer de controlo derivado, como a GridViewDesigner classe, que deve processar o conteúdo da região antes de chamar o GetDesignTimeHtml método.

Ver também

Aplica-se a

GetDesignTimeHtml()

Recupera a marcação HTML que é usada para representar o controlo no momento do design.

public:
 virtual System::String ^ GetDesignTimeHtml();
public virtual string GetDesignTimeHtml();
abstract member GetDesignTimeHtml : unit -> string
override this.GetDesignTimeHtml : unit -> string
Public Overridable Function GetDesignTimeHtml () As String

Devoluções

A marcação HTML era usada para representar o controlo no momento do design.

Exemplos

O seguinte exemplo de código demonstra como sobrescrever o GetDesignTimeHtml método num designer de controlo personalizado. Se a propriedade Texto do controlo associado estiver vazia, o GetDesignTimeHtml método chama o GetEmptyDesignTimeHtml método. Caso contrário, o GetDesignTimeHtml método cria e renderiza um controlo de Hyperlink.

public override string GetDesignTimeHtml()
{
    if (simpleControl.Text.Length > 0)
    {
        string spec = "<a href='{0}.aspx'>{0}</a>";
        return String.Format(spec, simpleControl.Text);
    }
    else
    {
        return GetEmptyDesignTimeHtml();
    }
}
Public Overrides Function GetDesignTimeHtml() As String
   ' Component is the instance of the component or control that
   ' this designer object is associated with. This property is 
   ' inherited from System.ComponentModel.ComponentDesigner.
   simpleControl = CType(Component, Simple)
   
   If simpleControl.Text.Length > 0 Then
      Dim sw As New StringWriter()
      Dim tw As New HtmlTextWriter(sw)
      
      Dim placeholderLink As New HyperLink()
      
      ' Put simpleControl.Text into the link's Text.
      placeholderLink.Text = simpleControl.Text
      placeholderLink.NavigateUrl = simpleControl.Text
      placeholderLink.RenderControl(tw)
      
      Return sw.ToString()
   Else
      Return GetEmptyDesignTimeHtml()
   End If
End Function

Notas para Herdeiros

Se estiver a criar um controlo de contentor personalizado, certifique-se de que renderiza o controlo e todos os controlos filhos no momento do design, independentemente de a Visible propriedade estar definida como true ou false.

Ver também

Aplica-se a