ControlStyles 列舉
定義
指定控制項的樣式和行為。Specifies the style and behavior of a control.
此列舉有 FlagsAttribute 屬性,因此其成員值可進行位元組合。
public enum class ControlStyles
[System.Flags]
public enum ControlStyles
[<System.Flags>]
type ControlStyles =
Public Enum ControlStyles
- 繼承
- 屬性
欄位
AllPaintingInWmPaint | 8192 | 如果為 |
CacheText | 16384 | 如果為 |
ContainerControl | 1 | 如果為 |
DoubleBuffer | 65536 | 如果為 |
EnableNotifyMessage | 32768 | 如果為 |
FixedHeight | 64 | 如果為 |
FixedWidth | 32 | 如果為 |
Opaque | 4 | 如果為 |
OptimizedDoubleBuffer | 131072 | 如果為 |
ResizeRedraw | 16 | 如果為 |
Selectable | 512 | 如果為 |
StandardClick | 256 | 如果為 |
StandardDoubleClick | 4096 | 如果為 |
SupportsTransparentBackColor | 2048 | 如果為 |
UserMouse | 1024 | 如果為 |
UserPaint | 2 | 如果為 |
UseTextForAccessibility | 262144 | 指定控制項的 |
範例
下列範例示範如何使用 ControlStyles 與 StyleChanged 事件。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,並且 OnPaintBackground OnPaint 會直接從視窗訊息 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. 您可以傳送視窗訊息 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 位設定為 true
。To 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.OnMouseDown 、 Control.OnMouseUp 、 Control.OnMouseEnter 、、、 Control.OnMouseMove Control.OnMouseHover Control.OnMouseLeave 和 Control.OnMouseWheel 。When 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. 但是, OnClick OnDoubleClick 不論 StandardClick 和 StandardDoubleClick 位值為何,控制項都可以呼叫或直接。However, the control can call OnClick or OnDoubleClick directly regardless of the StandardClick and StandardDoubleClick bit values. 如需有關控制項點擊和按兩下行為的詳細資訊,請參閱 Control.Click 和 Control.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. 某些內建的控制項類型(例如 TextBox 和 ComboBox )會重設此樣式,以便 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.