ControlStyles 列舉

定義

指定控制項的樣式和行為。Specifies the style and behavior of a control.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

public enum class ControlStyles
[System.Flags]
public enum ControlStyles
type ControlStyles = 
Public Enum ControlStyles
繼承
ControlStyles
屬性

欄位

AllPaintingInWmPaint 8192

如果為 true,控制項會忽略視窗訊息 WM_ERASEBKGND 以減少閃爍。If true, the control ignores the window message WM_ERASEBKGND to reduce flicker. 只有在 UserPaint 位元設定為 true 時,才應套用此樣式。This style should only be applied if the UserPaint bit is set to true.

CacheText 16384

如果為 true,控制項會保留文字的複本,而不是在每次需要時從 Handle 取得。If true, the control keeps a copy of the text rather than getting it from the Handle each time it is needed. 此樣式預設為 falseThis style defaults to false. 此行為可以改進效能,但會難以維持文字同步。This behavior improves performance, but makes it difficult to keep the text synchronized.

ContainerControl 1

如果為 true,控制項為類容器控制項。If true, the control is a container-like control.

DoubleBuffer 65536

如果為 true,會在緩衝區中執行繪製,並在完成之後,將結果輸出到畫面。If true, drawing is performed in a buffer, and after it completes, the result is output to the screen. 雙重緩衝可防止控制項重繪造成的閃爍。Double-buffering prevents flicker caused by the redrawing of the control. 如果您將 DoubleBuffer 設為 true,您也應該將 UserPaintAllPaintingInWmPaint 設為 trueIf you set DoubleBuffer to true, you should also set UserPaint and AllPaintingInWmPaint to true.

EnableNotifyMessage 32768

如果為 true,每個傳送至控制項之 WndProc(Message) 的訊息會呼叫 OnNotifyMessage(Message) 方法。If true, the OnNotifyMessage(Message) method is called for every message sent to the control's WndProc(Message). 此樣式預設為 falseThis style defaults to false. EnableNotifyMessage 無法在部分信任的情況執行。EnableNotifyMessage does not work in partial trust.

FixedHeight 64

如果為 true,當自動調整時控制項為固定高度。If true, the control has a fixed height when auto-scaled. 例如,如果配置作業嘗試要調整控制項以容納新的 Font,則控制項的 Height 會維持不變。For example, if a layout operation attempts to rescale the control to accommodate a new Font, the control's Height remains unchanged.

FixedWidth 32

如果為 true,當自動調整時控制項為固定寬度。If true, the control has a fixed width when auto-scaled. 例如,如果配置作業嘗試要調整控制項以容納新的 Font,則控制項的 Width 會維持不變。For example, if a layout operation attempts to rescale the control to accommodate a new Font, the control's Width remains unchanged.

Opaque 4

如果為 true,控制項會繪製為不透明且不會繪製背景。If true, the control is drawn opaque and the background is not painted.

OptimizedDoubleBuffer 131072

如果為 true,控制項會先繪製到緩衝區,而非直接繪製到螢幕,這可減少閃爍。If true, the control is first drawn to a buffer rather than directly to the screen, which can reduce flicker. 如果您將此屬性設為 true,您也應該將 AllPaintingInWmPaint 設為 trueIf you set this property to true, you should also set the AllPaintingInWmPaint to true.

ResizeRedraw 16

如果為 true,控制項調整大小時會重繪。If true, the control is redrawn when it is resized.

Selectable 512

如果為 true,控制項可以取得焦點。If true, the control can receive focus.

StandardClick 256

如果為 true,控制項會實作標準的 Click 行為。If true, the control implements the standard Click behavior.

StandardDoubleClick 4096

如果為 true,控制項會實作標準的 DoubleClick 行為。If true, the control implements the standard DoubleClick behavior. 如果 StandardClick 位元並未設為 true,則會忽略此樣式。This style is ignored if the StandardClick bit is not set to true.

SupportsTransparentBackColor 2048

如果為 true,控制項可接受 BackColor 與小於 255 的 Alpha 元件以模擬透明度。If true, the control accepts a BackColor with an alpha component of less than 255 to simulate transparency. 僅有 UserPaint 位元設為 true 且父控制項衍生自 Control 時,才會模擬透明度。Transparency will be simulated only if the UserPaint bit is set to true and the parent control is derived from Control.

UserMouse 1024

如果為 true,控制項會進行其本身的滑鼠處理,且作業系統不會處理滑鼠事件。If true, the control does its own mouse processing, and mouse events are not handled by the operating system.

UserPaint 2

如果為 true,控制項會繪製本身,而不是由作業系統進行。If true, the control paints itself rather than the operating system doing so. 如果為 false,就不會引發 Paint 事件。If false, the Paint event is not raised. 此樣式僅會套用至衍生自 Control 的類別。This style only applies to classes derived from Control.

UseTextForAccessibility 262144

指定控制項的 Text 屬性值,如果設定,會決定控制項的預設 Active Accessibility 名稱和快速鍵。Specifies that the value of the control's Text property, if set, determines the control's default Active Accessibility name and shortcut key.

範例

下列範例示範如何搭配 StyleChanged 事件使用 ControlStylesThe following example demonstrates a use of ControlStyles with the StyleChanged event.

private:
   // Set the 'FixedHeight' and 'FixedWidth' styles to false.
   void MyForm_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      this->SetStyle( ControlStyles::FixedHeight, false );
      this->SetStyle( ControlStyles::FixedWidth, false );
   }

   void RegisterEventHandler()
   {
      this->StyleChanged += gcnew EventHandler( this, &MyForm::MyForm_StyleChanged );
   }

   // Handle the 'StyleChanged' event for the 'Form'.
   void MyForm_StyleChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      MessageBox::Show( "The style releated to the 'Form' has been changed" );
   }
// Set the 'FixedHeight' and 'FixedWidth' styles to false.
private void MyForm_Load(object sender, EventArgs e)
{
   this.SetStyle(ControlStyles.FixedHeight, false);
   this.SetStyle(ControlStyles.FixedWidth, false);
}

private void RegisterEventHandler()
{
   this.StyleChanged += new EventHandler(MyForm_StyleChanged);
}

// Handle the 'StyleChanged' event for the 'Form'.
private void MyForm_StyleChanged(object sender, EventArgs e)
{
   MessageBox.Show("The style releated to the 'Form' has been changed");
}
' Set the 'FixedHeight' and 'FixedWidth' styles to false.
Private Sub MyForm_Load(sender As Object, e As EventArgs)
   Me.SetStyle(ControlStyles.FixedHeight, False)
   Me.SetStyle(ControlStyles.FixedWidth, False)
End Sub

Private Sub RegisterEventHandler()
   AddHandler Me.StyleChanged, AddressOf MyForm_StyleChanged
End Sub

' Handle the 'StyleChanged' event for the 'Form'.
Private Sub MyForm_StyleChanged(sender As Object, e As EventArgs)
   MessageBox.Show("The style releated to the 'Form' has been changed")
End Sub

備註

控制項在各種屬性和方法中使用這個列舉來指定功能。Controls use this enumeration in various properties and methods to specify functionality. 控制項可以藉由呼叫 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. 例如,下列 Visual Basic 程式程式碼會啟用雙重緩衝處理。For example, the following line of Visual Basic code would enable double-buffering.

myControl.SetStyle(UserPaint Or AllPaintingInWmPaint Or DoubleBuffer, True)  

如果 AllPaintingInWmPaint 位設定為 true,就會忽略視窗訊息 WM_ERASEBKGND,同時從視窗訊息 WM_PAINT 直接呼叫 OnPaintBackgroundOnPaint 方法。If the AllPaintingInWmPaint bit is set to true, the window message WM_ERASEBKGND is ignored, and both OnPaintBackground and OnPaint methods are called directly from the window message WM_PAINT. 這通常會減少閃爍,除非其他控制項將視窗訊息 WM_ERASEBKGND 傳送至控制項。This generally reduces flicker unless other controls send the window message WM_ERASEBKGND to the control. 您可能會將視窗訊息 WM_ERASEBKGRND,以達到與 SupportsTransparentBackColor 類似的虛擬透明效果;例如,具有平面外觀的 ToolBar 會執行此工作。You might send the window message WM_ERASEBKGRND to achieve a pseudo-transparent effect similar to SupportsTransparentBackColor; for example, a ToolBar with flat appearance does this.

若要完全啟用雙重緩衝處理,您可以將 OptimizedDoubleBuffer 和 AllPaintingInWmPaint 位設定為 trueTo fully enable double-buffering, you can set the OptimizedDoubleBuffer and AllPaintingInWmPaint bits to true. 不過,啟用雙重緩衝的慣用方法會產生相同的結果,就是將控制項的 [DoubleBuffered] 屬性設定為 [true]。However the preferred method for enabling double buffering, which yields the same result, is to set the DoubleBuffered property for the control to true.

如果 SupportsTransparentBackColor 位設定為 true,且 BackColor 設定為其 Alpha 元件小於255的色彩,OnPaintBackground 會要求其父控制項繪製背景來模擬透明度。If the SupportsTransparentBackColor bit is set to true, and the BackColor is set to a color whose alpha component is less than 255, OnPaintBackground will simulate transparency by asking its parent control to paint the background. 這不是真正的透明度。This is not true transparency.

注意

如果控制項與其父系之間有另一個控制項,目前的控制項將不會在中間顯示控制項。If there is another control between the control and its parent, the current control will not show the control in the middle.

當 UserMouse 位設定為 true時,仍然會呼叫下列方法: Control.OnMouseDownControl.OnMouseUpControl.OnMouseEnterControl.OnMouseMoveControl.OnMouseHoverControl.OnMouseLeaveControl.OnMouseWheelWhen the UserMouse bit is set to true, the following methods are still called: Control.OnMouseDown, Control.OnMouseUp, Control.OnMouseEnter, Control.OnMouseMove, Control.OnMouseHover, Control.OnMouseLeave, and Control.OnMouseWheel.

按一下控制項時,如果 StandardClick 位設定為 true 則會呼叫 Control.OnClick 方法,並引發 Control.Click 事件。When the control is clicked, if the StandardClick bit is set to true the Control.OnClick method is called and it raises the Control.Click event. 當按兩下控制項,而且 StandardClick 和 StandardDoubleClick 位都設為 true時,就會將 click 傳遞至 DoubleClick 事件。When the control is double-clicked, and both the StandardClick and StandardDoubleClick bits are set to true, the click is passed on to the DoubleClick event. 然後會呼叫 Control.OnDoubleClick 方法,並引發 Control.DoubleClick 事件。Then the Control.OnDoubleClick method is called and it raises the Control.DoubleClick event. 不過,不論 StandardClick 和 StandardDoubleClick 位值為何,控制項都可以直接呼叫 OnClickOnDoubleClickHowever, the control can call OnClick or OnDoubleClick directly regardless of the StandardClick and StandardDoubleClick bit values. 如需按一下 ctrl 和按兩下行為的詳細資訊,請參閱 Control.ClickControl.DoubleClick 主題。For more information on control click and double click behaviors, see the Control.Click and Control.DoubleClick topics.

當設定 UseTextForAccessibility 位且控制項的 Text 屬性中有一個值時,該控制項的 Text 屬性值會決定控制項的預設 Active Accessibility 名稱和快速鍵。When the UseTextForAccessibility bit is set and there is a value in the control's Text property, the value of that control's Text property determines the control's default Active Accessibility name and shortcut key. 否則,將會改用先前 Label 控制項的文字。Otherwise, the text of the preceding Label control will be used instead. 預設會設定此樣式。This style is set by default. 某些內建控制項類型(例如 TextBoxComboBox)會重設此樣式,讓 Active Accessibility 不會使用這些控制項的 Text 屬性。Certain built-in control types, such as TextBox and ComboBox, reset this style so that the Text property of those controls will not be used by Active Accessibility.

適用於

另請參閱