Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Control.SetStyle Method

Sets the specified style bit to the specified value.

[Visual Basic]
Protected Sub SetStyle( _
   ByVal flag As ControlStyles, _
   ByVal value As Boolean _
)
[C#]
protected void SetStyle(
 ControlStyles flag,
 bool value
);
[C++]
protected: void SetStyle(
 ControlStyles flag,
 bool value
);
[JScript]
protected function SetStyle(
   flag : ControlStyles,
 value : Boolean
);

Parameters

flag
The ControlStyles bit to set.
value
true to apply the specified style to the control; otherwise, false.

Remarks

Control style bit flags are used to categorize supported behavior. 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. To determine the value assigned to a specified ControlStyles bit, use the GetStyle method and pass in the ControlStyles member to evaluate.

CAUTION   Setting the control style bits can substantially change the behavior of the control. Review the ControlStyles enumeration documentation to understand the effects of changing the control style bits before calling the SetStyle method.

Example

[Visual Basic, C#, C++] The following example enables double-buffering on a Form and updates the styles to reflect the changes.

[Visual Basic] 
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

[C#] 
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();
}

[C++] 
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();
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Windows.Forms Namespace | GetStyle | ControlStyles

Show:
© 2014 Microsoft. All rights reserved.