J
Jay B. Harlow [MVP - Outlook]
Matthew,
The only way I know of to change the Default is to derive a new class from
the original & override the value. Then use this new class on my forms
instead of the original.
Something like:
Imports System.ComponentModel
Public Class ButtonEx
Inherits System.Windows.Form.Button
Public Sub New()
MyBase.FlatStyle = FlatStyle.System
End Sub
<DefaultValue(GetType(FlatStyle), "System")> _
Public Shadows Property FlatStyle() As FlatStyle
Get
Return MyBase.FlatStyle
End Get
Set(ByVal value As FlatStyle)
MyBase.FlatStyle = value
End Set
End Property
End Class
Then every place I would have used a System.Windows.Form.Button I would use
a ButtonEx instead.
Note ButtonBase.FlatStyle is not defined as overridable so we have to
Shadows it here. Ideally we want to use Overrides instead of Shadows,
however Shadows here is OK as we are simply delegating the base property!
The reason we need the DefaultValue attribute on it to let the Designer know
that the FlatStyle value has a default value of System (not Standard as
Button has). Even with Shadows the designer is able to use the other
attributes it needs from ButtonBase.FlatStyle.
You can apply the same code to extended Label, CheckBox, RadioButton, and
GroupBox controls also.
Hope this helps
Jay
The only way I know of to change the Default is to derive a new class from
the original & override the value. Then use this new class on my forms
instead of the original.
Something like:
Imports System.ComponentModel
Public Class ButtonEx
Inherits System.Windows.Form.Button
Public Sub New()
MyBase.FlatStyle = FlatStyle.System
End Sub
<DefaultValue(GetType(FlatStyle), "System")> _
Public Shadows Property FlatStyle() As FlatStyle
Get
Return MyBase.FlatStyle
End Get
Set(ByVal value As FlatStyle)
MyBase.FlatStyle = value
End Set
End Property
End Class
Then every place I would have used a System.Windows.Form.Button I would use
a ButtonEx instead.
Note ButtonBase.FlatStyle is not defined as overridable so we have to
Shadows it here. Ideally we want to use Overrides instead of Shadows,
however Shadows here is OK as we are simply delegating the base property!
The reason we need the DefaultValue attribute on it to let the Designer know
that the FlatStyle value has a default value of System (not Standard as
Button has). Even with Shadows the designer is able to use the other
attributes it needs from ButtonBase.FlatStyle.
You can apply the same code to extended Label, CheckBox, RadioButton, and
GroupBox controls also.
Hope this helps
Jay
Matthew said:I normally set them in the designer, however you should be able to useIs there a programmatic way to change all my buttons and stuff to
flatstyle.system?
something like:
Code:[/QUOTE] I just noticed this slows the load time of my program by over a second! Changing the flatstyle in the designer is looking more attractive all the time. Is there a way to change the default flatstyle in the designer? Matthew [/QUOTE]