Control.SetStyle(ControlStyles, Boolean) Method

Definition

将指定的 ControlStyles 标志设置为 truefalseSets a specified ControlStyles flag to either true or false.

protected:
 void SetStyle(System::Windows::Forms::ControlStyles flag, bool value);
protected void SetStyle (System.Windows.Forms.ControlStyles flag, bool value);
member this.SetStyle : System.Windows.Forms.ControlStyles * bool -> unit
Protected Sub SetStyle (flag As ControlStyles, value As Boolean)

Parameters

flag
ControlStyles

要设置的 ControlStyles 位。The ControlStyles bit to set.

value
Boolean

true 表示将指定的样式应用于控件;false 表示不应用。true to apply the specified style to the control; otherwise, false.

Examples

下面的代码示例对 Form 启用双缓冲,并更新样式以反映所做的更改。The following code example enables double-buffering on a Form and updates the styles to reflect the changes.

public:
   void EnableDoubleBuffering()
   {
      // Set the value of the double-buffering style bits to true.
      this->SetStyle( static_cast<ControlStyles>(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint), true );
      this->UpdateStyles();
   }
public void EnableDoubleBuffering()
{
   // Set the value of the double-buffering style bits to true.
   this.SetStyle(ControlStyles.DoubleBuffer | 
      ControlStyles.UserPaint | 
      ControlStyles.AllPaintingInWmPaint,
      true);
   this.UpdateStyles();
}
Public Sub EnableDoubleBuffering()
   ' Set the value of the double-buffering style bits to true.
   Me.SetStyle(ControlStyles.DoubleBuffer _
     Or ControlStyles.UserPaint _
     Or ControlStyles.AllPaintingInWmPaint, _
     True)
   Me.UpdateStyles()
End Sub

Remarks

控件样式位标志用于对支持的行为进行分类。Control style bit flags are used to categorize supported behavior. 控件可以通过调用 SetStyle 方法,并传入适当的 ControlStyles 位(或位)和布尔值来启用样式,以将位设置为。A control can enable a style by calling the SetStyle method and passing in the appropriate ControlStyles bit (or bits) and the Boolean value to set the bit(s) to. 若要确定赋给指定 ControlStyles 位的值,请使用 GetStyle 方法并传入要计算的 ControlStyles 成员。To determine the value assigned to a specified ControlStyles bit, use the GetStyle method and pass in the ControlStyles member to evaluate.

Caution

设置控件样式位可能会显著改变控件的行为。Setting the control style bits can substantially change the behavior of the control. 在调用 SetStyle 方法之前,请查看 ControlStyles 枚举文档以了解更改控件样式位的影响。Review the ControlStyles enumeration documentation to understand the effects of changing the control style bits before calling the SetStyle method.

Applies to

See also