Lire en anglais

Partager via


DesignerAutoFormat.Apply(Control) Méthode

Définition

Applique la mise en forme associée au contrôle spécifié.

C#
public abstract void Apply(System.Web.UI.Control control);

Paramètres

control
Control

Contrôle serveur Web auquel la mise en forme est appliquée.

Exemples

L’exemple de code suivant montre comment utiliser un DesignerAutoFormat objet pour appliquer la mise en forme à un contrôle serveur Web.

C#
// Applies styles based on the Name of the AutoFormat
public override void Apply(Control inLabel)
{
    if (inLabel is IndentLabel)
    {
        IndentLabel ctl = (IndentLabel)inLabel;

        // Apply formatting according to the Name
        if (this.Name == "MyClassic")
        {
            // For MyClassic, apply style elements directly to the control
            ctl.ForeColor = Color.Gray;
            ctl.BackColor = Color.LightGray;
            ctl.Font.Size = FontUnit.XSmall;
            ctl.Font.Name = "Verdana,Geneva,Sans-Serif";
        }
        else if (this.Name == "MyBright")
        {
            // For MyBright, apply style elements to the Style property
            this.Style.ForeColor = Color.Maroon;
            this.Style.BackColor = Color.Yellow;
            this.Style.Font.Size = FontUnit.Medium;

            // Merge the AutoFormat style with the control's style
            ctl.MergeStyle(this.Style);
        }
        else
        {
            // For the Default format, apply style elements to the control
            ctl.ForeColor = Color.Black;
            ctl.BackColor = Color.Empty;
            ctl.Font.Size = FontUnit.XSmall;
        }
    }
}

Remarques

La Apply méthode applique la mise en forme au contrôle spécifié en fonction de la Name propriété . Vous pouvez appliquer les styles directement au contrôle, ou définir la Style propriété, puis utiliser la MergeStyle méthode pour le contrôle afin d’appliquer les modifications de style au contrôle.

Notes pour les responsables de l’implémentation

Lorsque vous héritez de la DesignerAutoFormat classe , vous devez remplacer la Apply(Control) méthode .

S’applique à

Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

Voir aussi