Control.SetStyle(ControlStyles, Boolean) 方法

定義

將指定的 ControlStyles 旗標設定為 truefalse

C#
protected void SetStyle(System.Windows.Forms.ControlStyles flag, bool value);

參數

flag
ControlStyles

要設定的 ControlStyles 位元。

value
Boolean

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

範例

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

C#
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();
}

備註

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

警告

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

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱