Class

  • Thread starter Thread starter ucasesoftware
  • Start date Start date
U

ucasesoftware

In my planning i have 10 colors will never change (one by category)

255;128;128
255;192;128
255;255;128
LightGreen
LightBlue
CornflowerBlue
HotPink
231; 231; 214
Plum
Peru


What is the best way to use them in my class ?
property ? array ? ennum ?
 
ucasesoftware said:
In my planning i have 10 colors will never change (one by category)

255;128;128
255;192;128
255;255;128
LightGreen
LightBlue
CornflowerBlue
HotPink
231; 231; 214
Plum
Peru


What is the best way to use them in my class ?
property ? array ? ennum ?

Enum I suppose, call it something like UIColors (or if you must
MyColors (ugh)) and then name each member according to what it means
*to you*. Take SystemColors as your model - so you would have
UIColors.FrameColor = Color.LightGreen etc etc
 
i try enum
but if i have

Enum UIColors
cat1
cat2
cat3
cat4
cat5
cat6
cat7
cat8
cat9
cat10
End Enum

the enum have the key... but where i stock the values ?
 
is that better ?


ReadOnly Property colorCat1() As Color
Get
Return System.Drawing.Color.FromArgb(CType(255, Byte),
CType(128, Byte), CType(128, Byte))
End Get
End Property

and color2, color3....
 
ucasesoftware said:
is that better ?


ReadOnly Property colorCat1() As Color
Get
Return System.Drawing.Color.FromArgb(CType(255, Byte),
CType(128, Byte), CType(128, Byte))
End Get
End Property

and color2, color3....

Sorry, yes, I don't know what I was thinking before. What you have will
work, although I would make them Shared properties of a class:

Public Class UIColors

Public Shared ReadOnly Property Color1() As Color
Get
Return Color.LightBlue
End Get
End Property

Public Shared ReadOnly Property Color2() As Color
Get
Return Color.LightGray
End Get
End Property

'...

End Class


This way you can just refer to UIColors.Color1 without having to
instantiate an object
 
ucasesoftware said:
In my planning i have 10 colors will never change (one by category)

255;128;128
255;192;128
255;255;128
LightGreen
LightBlue
CornflowerBlue
HotPink
231; 231; 214
Plum
Peru


What is the best way to use them in my class ?
property ? array ? ennum ?

\\\
Private ReadOnly BlaColor As Color = Color.FromArgb(...)
....
///
 
ucasesoftware,
In addition to the other comments, I would simply create a type that has
readonly properties or fields of type Color.

Something like:

Public NotInheritable Class UIColors

Private Sub New()

End Sub

Public Shared ReadOnly Category1 As Color = Color.FromArgb(255, 128,
128)
Public Shared ReadOnly Category2 As Color = Color.FromArgb(255, 192,
128)
Public Shared ReadOnly Category3 As Color = Color.FromArgb(255, 255,
128)
Public Shared ReadOnly Category4 As Color = Color.LightGreen
Public Shared ReadOnly Category5 As Color = Color.LightBlue
Public Shared ReadOnly Category6 As Color = Color.CornflowerBlue
Public Shared ReadOnly Category7 As Color = Color.HotPink
Public Shared ReadOnly Category8 As Color = Color.FromArgb(231, 231,
214)
Public Shared ReadOnly Category9 As Color = Color.Plum
Public Shared ReadOnly Category10 As Color = Color.Peru

End Class

The "NotInheritable" prevents others from inheriting from UIColors, the
"Private Sub New" prevents others from instantiating UIColors, while "Class"
requires others to qualify the usage of the members. The "Shared" allows you
to use the values without instantiating the class, while the "ReadOnly"
prevents others from assigning a value to the field (effectively making it a
constant value).

Then to use each member you simply use the value.

Me.BackColor = UIColors.Category1
Me.ForeColor = UIColors.Category6


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| In my planning i have 10 colors will never change (one by category)
|
| 255;128;128
| 255;192;128
| 255;255;128
| LightGreen
| LightBlue
| CornflowerBlue
| HotPink
| 231; 231; 214
| Plum
| Peru
|
|
| What is the best way to use them in my class ?
| property ? array ? ennum ?
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top