Control.SetStyle 方法
将指定的样式位设置为指定值。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Protected Sub SetStyle ( _
flag As ControlStyles, _
value As Boolean _
)
用法
Dim flag As ControlStyles
Dim value As Boolean
Me.SetStyle(flag, value)
protected void SetStyle (
ControlStyles flag,
bool value
)
protected:
void SetStyle (
ControlStyles flag,
bool value
)
protected void SetStyle (
ControlStyles flag,
boolean value
)
protected function SetStyle (
flag : ControlStyles,
value : boolean
)
参数
- flag
要设置的 ControlStyles 位。
- value
true 表示将指定的样式应用于控件;false 表示不应用。
备注
控件样式位标志用于对支持的行为进行分类。控件可以通过调用 SetStyle 方法并传入适当的 ControlStyles 位以及设置该位的 Boolean 值来启用样式。若要确定分配给指定的 ControlStyles 位的值,请使用 GetStyle 方法并传入要计算的 ControlStyles 成员。
警告
设置控件样式位能够充分地更改控件行为。查看 ControlStyles 枚举文档可以了解在调用 SetStyle 方法之前更改控件样式位产生的影响。
示例
下面的代码示例启用 Form 上的双缓冲,并更新样式以反映所做的更改。
Public Sub EnableDoubleBuffering()
' Set the value of the double-buffering style bits to true.
Me.SetStyle(ControlStyles.DoubleBuffer _
Or ControlStyles.UserPaint _
Or ControlStyles.AllPaintingInWmPaint, _
True)
Me.UpdateStyles()
End Sub
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,
true);
this.UpdateStyles();
}
public:
void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this->SetStyle( static_cast<ControlStyles>(ControlStyles::DoubleBuffer | ControlStyles::UserPaint | ControlStyles::AllPaintingInWmPaint), true );
this->UpdateStyles();
}
public void EnableDoubleBuffering()
{
// Set the value of the double-buffering style bits to true.
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
this.UpdateStyles();
} //EnableDoubleBuffering
平台
Windows 98、Windows 2000 SP4、Windows Millennium Edition、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
Control 类
Control 成员
System.Windows.Forms 命名空间
GetStyle
ControlStyles