ControlStyles 枚举

定义

指定控件的样式和行为。

此枚举支持其成员值的按位组合。

public enum class ControlStyles
[System.Flags]
public enum ControlStyles
[<System.Flags>]
type ControlStyles = 
Public Enum ControlStyles
继承
ControlStyles
属性

字段

AllPaintingInWmPaint 8192

如果为 true,则控件忽略窗口消息 WM_ERASEBKGND 以减少闪烁。 仅当将 UserPaint 位设置为 true 时,才应用此样式。

CacheText 16384

如果为 true,则控件将保留文本的副本,而不是每次必需时从 Handle 中获取。 此样式默认为 false。 此行为可提高性能,但很难保持文本同步。

ContainerControl 1

如果为 true,则控件是类容器控件。

DoubleBuffer 65536

如果为 true,则在缓冲区中进行绘制,并且完成后将结果输出到屏幕。 双缓冲可以防止因重绘控件而引起的闪烁。 如果将 DoubleBuffer 设置为 true,则还应将 UserPaintAllPaintingInWmPaint 设置为 true

EnableNotifyMessage 32768

如果为 true,则将对发送到控件的 WndProc(Message) 的每个消息调用 OnNotifyMessage(Message) 方法。 此样式默认为 falseEnableNotifyMessage 在部分信任中不起作用。

FixedHeight 64

如果为 true,则控件在自动缩放时具有固定高度。 例如,如果布局操作尝试重新缩放控件以适应新的 Font,则控件的 Height 保持不变。

FixedWidth 32

如果为 true,则控件在自动缩放时具有固定宽度。 例如,如果布局操作尝试重新缩放控件以适应新的 Font,则控件的 Width 保持不变。

Opaque 4

如果为 true,则控件会绘制为不透明,且不绘制背景。

OptimizedDoubleBuffer 131072

如果为 true,则控件将首先绘制到缓冲区而不是直接绘制到屏幕,这可以减少闪烁。 如果将此属性设置为 true,则还应将 AllPaintingInWmPaint 设置为 true

ResizeRedraw 16

如果为 true,则控件会在调整大小时进行重绘。

Selectable 512

如果为 true,则控件可以接收焦点。

StandardClick 256

如果为 true,则控件实现标准 Click 行为。

StandardDoubleClick 4096

如果为 true,则控件实现标准 DoubleClick 行为。 如果未将 StandardClick 位设置为 true,则忽略此样式。

SupportsTransparentBackColor 2048

如果为 true,则控件接受 alpha 组件数小于 255 个的 BackColor 来模拟透明度。 仅当将 UserPaint 位设置为 true 且父控件从 Control 派生时,才会模拟透明度。

UserMouse 1024

如果为 true,则将由控件而不是操作系统处理其自身的鼠标事件。

UserPaint 2

如果为 true,则会由控件而不是由操作系统来绘制控件自身。 如果 false,则不会引发 Paint 事件。 此样式仅适用于从 Control 派生的类。

UseTextForAccessibility 262144

指定控件的 Text 属性的值,若设置,则确定控件的默认 Active Accessibility 名称和快捷键。

示例

以下示例演示如何将 与 ControlStyles 事件一起使用 StyleChanged

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

注解

控件在各种属性和方法中使用此枚举来指定功能。 控件可以通过调用 SetStyle 方法并传入相应的 ControlStyles 位 (或位) 和布尔值来启用样式,以将位 () 设置为 。 例如,以下 Visual Basic 代码行将启用双重缓冲。

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

如果将 AllPaintingInWmPaint 位设置为 true,则会忽略窗口消息WM_ERASEBKGND,并且 OnPaintBackground 直接从窗口消息WM_PAINT调用 和 OnPaint 方法。 这通常会减少闪烁,除非其他控件将窗口消息WM_ERASEBKGND发送到控件。 可以WM_ERASEBKGRND发送窗口消息,以实现类似于 SupportsTransparentBackColor 的伪透明效果;例如, ToolBar 具有平面外观的 执行此操作。

若要完全启用双缓冲,可以将 OptimizedDoubleBuffer 和 AllPaintingInWmPaint 位设置为 true。 但是,启用双重缓冲(生成相同结果)的首选方法是将 控件的 属性设置为 DoubleBufferedtrue

如果 SupportsTransparentBackColor 位设置为 true,并且 BackColor 设置为 alpha 分量小于 255 的颜色, OnPaintBackground 则通过要求其父控件绘制背景来模拟透明度。 这不是真正的透明度。

注意

如果控件与其父控件之间有另一个控件,则当前控件不会在中间显示该控件。

将 UserMouse 位设置为 true时,仍会调用以下方法:Control.OnMouseDown、、Control.OnMouseUpControl.OnMouseEnterControl.OnMouseMoveControl.OnMouseHoverControl.OnMouseLeaveControl.OnMouseWheel

单击控件时,如果 StandardClick 位设置为 true 方法, Control.OnClick 则会调用 并引发 Control.Click 事件。 双击控件并且 StandardClick 和 StandardDoubleClick 位都设置为 true时,单击将传递给 DoubleClick 事件。 然后调用 Control.OnDoubleClick 方法,并引发 Control.DoubleClick 事件。 但是,无论 StandardClick 和 StandardDoubleClick 位值如何,控件都可以调用 OnClickOnDoubleClick 直接。 有关控件单击和双击行为的详细信息,请参阅 Control.ClickControl.DoubleClick 主题。

设置 UseTextForAccessibility 位并且控件的 Text 属性中有一个值时,该控件 Text 的 属性的值将确定控件的默认 Active Accessibility 名称和快捷键。 否则,将改用上述 Label 控件的文本。 默认设置此样式。 某些内置控件类型(如 TextBoxComboBox)会重置此样式, Text 以便活动辅助功能不会使用这些控件的属性。

适用于

另请参阅