Control.SetStyle(ControlStyles, Boolean) Control.SetStyle(ControlStyles, Boolean) Control.SetStyle(ControlStyles, Boolean) Control.SetStyle(ControlStyles, Boolean) Method

定义

将指定的 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)

参数

value
Boolean Boolean Boolean Boolean

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

示例

下面的代码示例启用对的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

注解

控件样式位标志用于对支持的行为进行分类。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.

注意

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

适用于

另请参阅