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位 (或 bits) 和要设置该位的布尔值。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枚举文档以了解更改之前调用的控件样式位的效果SetStyle方法。Review the ControlStyles enumeration documentation to understand the effects of changing the control style bits before calling the SetStyle method.

适用于

另请参阅