Share via


ListControlDesigner.GetDesignTimeHtml Méthode

Définition

Obtient le code HTML utilisé pour représenter le contrôle au moment du design.

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

Retours

String contenant le balisage utilisé pour restituer le contrôle dérivé du ListControl au moment du design.

Exemples

L’exemple de code suivant remplace la GetDesignTimeHtml méthode pour personnaliser le balisage affiché pour le contrôle associé sur une aire de conception. Si la BackColor propriété n’est pas définie pour le contrôle associé, elle est définie sur Gainsboroet le contrôle est affiché avec cette couleur d’arrière-plan. Une fois cette opération effectuée, l’implémentation de base de la GetDesignTimeHtml méthode est appelée.

Cet exemple de code fait partie d’un exemple plus grand fourni pour la ListControlDesigner classe .

// Create the markup to display the control on the design surface. 
public override string GetDesignTimeHtml()
{
    string designTimeMarkup = null;

    // Create variables to access the control
    // item collection and back color.
    ListItemCollection items = simpleRadioButtonList.Items;
    Color oldBackColor = simpleRadioButtonList.BackColor;

    // Check the property values and render the markup
    // on the design surface accordingly.
    try
    {
        if (oldBackColor == Color.Empty)
            simpleRadioButtonList.BackColor = Color.Gainsboro;

        if (changedDataSource)
            items.Add("Updated to a new data source: " + 
                DataSource + ".");

        // Call the base method to generate the markup.
        designTimeMarkup = base.GetDesignTimeHtml();
    }
    catch (Exception ex)
    {
        // Catch any exceptions that occur.
        designTimeMarkup = GetErrorDesignTimeHtml(ex);
    }
    finally
    {
        // Set the properties back to their original state.
        simpleRadioButtonList.BackColor = oldBackColor;
        items.Clear();
    }

    return designTimeMarkup;
} // GetDesignTimeHtml
' Create the markup to display the control on the design surface.
Public Overrides Function GetDesignTimeHtml() As String

    Dim designTimeHtml As String = String.Empty

    ' Create variables to access the control's
    ' item collection and back color. 
    Dim items As ListItemCollection = simpleRadioButtonList.Items
    Dim oldBackColor As Color = simpleRadioButtonList.BackColor

    ' Check the property values and render the markup
    ' on the design surface accordingly.
    Try
        If (Color.op_Equality(oldBackColor, Color.Empty)) Then
            simpleRadioButtonList.BackColor = Color.Gainsboro
        End If

        If (changedDataSource) Then
            items.Add( _
                "Updated to a new data source: " & DataSource & ".")
        End If

        designTimeHtml = MyBase.GetDesignTimeHtml()

    Catch ex As Exception
        ' Catch any exceptions that occur.
        MyBase.GetErrorDesignTimeHtml(ex)

    Finally
        ' Set the properties back to their original state.
        simpleRadioButtonList.BackColor = oldBackColor
        items.Clear()
    End Try

    Return designTimeHtml
End Function ' GetDesignTimeHtml

Remarques

Si le contrôle associé dérivé de l’objet ListControl est lié aux données, la GetDesignTimeHtml méthode efface la Items collection et ajoute un String message indiquant que le contrôle est lié aux données. Si le contrôle associé n’est pas lié aux données et que la Items collection est vide, ajoute GetDesignTimeHtml un String message indiquant que le contrôle est indépendant. Ensuite, le GetDesignTimeHtml appelle sa méthode de base pour générer le balisage.

S’applique à

Voir aussi