Прочитај на енглеском Уреди

Делите путем


DesignerAutoFormat.Apply(Control) Method

Definition

Applies the associated formatting to the specified control.

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

Parameters

control
Control

A Web server control to apply the formatting to.

Examples

The following code example illustrates how to use a DesignerAutoFormat object to apply formatting to a Web server control.

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;
        }
    }
}

Remarks

The Apply method applies formatting to the specified control based on the Name property. You can apply the styles directly to the control, or set the Style property and then use the MergeStyle method for the control to apply the style changes to the control.

Notes to Implementers

When you inherit from the DesignerAutoFormat class, you must override the Apply(Control) method.

Applies to

Производ Верзије
.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

See also