ControlStyles Enum

Definition

指定控件的样式和行为。Specifies the style and behavior of a control.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

public enum class ControlStyles
[System.Flags]
public enum ControlStyles
type ControlStyles = 
Public Enum ControlStyles
Inheritance
ControlStyles
Attributes

Fields

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,则控件接受 alpha 组件数小于 255 个的 BackColor 来模拟透明度。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.

Examples

下面的示例演示如何将 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

Remarks

控件在各种属性和方法中使用此枚举来指定功能。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 以实现类似于 Controlstyles.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 属性设置为 trueHowever the preferred method for enabling double buffering, which yields the same result, is to set the DoubleBuffered property for the control to true.

如果将 Controlstyles.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.

Note

如果控件与其父控件之间有另一个控件,则当前控件将不会在中间显示控件。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时,单击会传递到 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. 有关控件单击和双击行为的详细信息,请参阅 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.

Applies to

See also