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.

範例

下列範例示範的用法ControlStylesStyleChanged事件。The 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 會被忽略,並同時OnPaintBackgroundOnPaint會直接從視窗訊息 WM_PAINT 呼叫方法。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. 您可能會傳送以達到類似於 SupportsTransparentBackColor; 虛擬透明效果的視窗訊息 WM_ERASEBKGRND比方說,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屬性的控制項trueHowever 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. 這不是,則為 true 的透明度。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.OnMouseLeave,以及Control.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 位元設為trueControl.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,按一下會傳遞給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. 不過,可以呼叫控制項OnClickOnDoubleClick直接而不論 StandardClick 與 StandardDoubleClick 位元值。However, the control can call OnClick or OnDoubleClick directly regardless of the StandardClick and StandardDoubleClick bit values. 如需詳細資訊,在控制項上按一下和按兩下行為,請參閱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,重設此樣式,讓Text的這些控制項的屬性不會使用由 Active Accessibility。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.

適用於

另請參閱