次の方法で共有


DesignerAutoFormat.Apply(Control) メソッド

定義

関連付けられている書式を指定したコントロールに適用します。

public:
 abstract void Apply(System::Web::UI::Control ^ control);
public abstract void Apply(System.Web.UI.Control control);
abstract member Apply : System.Web.UI.Control -> unit
Public MustOverride Sub Apply (control As Control)

パラメーター

control
Control

書式設定を適用する Web サーバー コントロール。

次のコード例は、 DesignerAutoFormat オブジェクトを使用して Web サーバー コントロールに書式設定を適用する方法を示しています。

// 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;
        }
    }
}
' Applies styles based on the Name of the AutoFormat
Public Overrides Sub Apply(ByVal inLabel As Control)
    If TypeOf inLabel Is IndentLabel Then
        Dim ctl As IndentLabel = CType(inLabel, IndentLabel)

        ' Apply formatting according to the Name
        If Me.Name.Equals("MyClassic") Then
            ' 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"
        ElseIf Me.Name.Equals("MyBright") Then
            ' For MyBright, apply style elements to the Style object
            Me.Style.ForeColor = Color.Maroon
            Me.Style.BackColor = Color.Yellow
            Me.Style.Font.Size = FontUnit.Medium

            ' Merge the AutoFormat style with the control's style
            ctl.MergeStyle(Me.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
        End If
    End If
End Sub

注釈

Apply メソッドは、Name プロパティに基づいて、指定したコントロールに書式を適用します。 コントロールにスタイルを直接適用するか、 Style プロパティを設定してから、コントロールの MergeStyle メソッドを使用して、スタイルの変更をコントロールに適用できます。

注意 (実装者)

DesignerAutoFormat クラスから継承する場合は、Apply(Control) メソッドをオーバーライドする必要があります。

適用対象

こちらもご覧ください