Control.SetStyle(ControlStyles, Boolean) 方法

定義

將指定的 ControlStyles 旗標設定為 truefalse

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)

參數

flag
ControlStyles

要設定的 ControlStyles 位元。

value
Boolean

true 會將指定的樣式套用至控制項,否則為 false

範例

下列程式碼範例會在 上 Form 啟用雙緩衝處理,並更新樣式以反映變更。

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

備註

控制項樣式位旗標可用來分類支援的行為。 控制項可以呼叫 方法來啟用樣式, SetStyle 並傳入適當的 ControlStyles 位 (或位) 和布林值,以將位 () 設定為 。 若要判斷指派給指定 ControlStyles 位的值,請使用 GetStyle 方法並傳入 ControlStyles 成員來評估。

警告

設定控制項樣式位可能會大幅變更控制項的行為。 請檢閱 ControlStyles 列舉檔,以瞭解在呼叫 SetStyle 方法之前變更控制項樣式位的效果。

適用於

另請參閱