Forms looks consistency

seema.nare@oasis-bs.com

Active member
Joined
May 19, 2006
Messages
27
Programming Experience
Beginner
I am using the background images in my application. And I want different labels in my application with some defined colors eg My every title in application should be of verdana 14pt Blue color, subtitile in arial 12pt Black color.
In short I want to implement it silmilar to .css in web pages.How could I implement that in VB.net application ?

I am NOT looking for the code like this

Sub Stylize(frm As Form)
Dim Con As Control
For i = 0 To frm.Controls.Count - 1
Con = frm.Controls(i)
If TypeOf Con Is TextBox Then Con.ForeColor = Color.Red
If TypeOf Con Is Button Then Con.FlatStyle = FlatStyle.Flat
Next
End Sub

Bcas my label can be of "Title", "SubTitle"

Any solution?
 
create a "style" class?

How about creating some sort of style class?

For example

VB.NET:
public class StyleClass

public sub New
end sub

public shared function SetTitleStyle(ctrl as control) as control
  with ctrl
    .ForeColor = Color.Red
    .FlatStyle = FlatStyle.Flat
  end with
  return ctrl
end function

....

end class
And in your windows form you can then do something like this:

me.TitleLabel = StyleClass.SetTitleStyle(me.TitleLabel)

Another way is to pass the control by reference this way you don't need a function, so a sub will sufice (although this is more a vb6 kind of programming)

kind regards,

Filip
 
Back
Top