-
Jun 23rd, 2014, 10:04 AM
#1
Thread Starter
Addicted Member
KnownColor vs SystemColors/Color?
What's the difference in using KnownColor vs SystemColors.. I cannot find any information on it in the VS help..
So why should one use Dim backColor As Color = Color.FromKnownColor(KnownColor.Highlight) and not Dim backColor As Color = SystemColors.Highlight?
I don't see the whole point of using KnownColor at all...
-
Jun 23rd, 2014, 10:18 AM
#2
Re: KnownColor vs SystemColors/Color?
I tested both like this:
Code:
Dim sw As Stopwatch = New Stopwatch
Dim backcolor As Color
sw.Start()
For i As Integer = 1 To 1000000
backcolor = SystemColors.Highlight
Next
sw.Stop()
Console.WriteLine(String.Format("It took: {0} milliseconds using SystemColors", sw.ElapsedMilliseconds))
sw = Stopwatch.StartNew
For i As Integer = 1 To 1000000
backcolor = Color.FromKnownColor(KnownColor.Highlight)
Next
sw.Stop()
Console.WriteLine(String.Format("It took: {0} milliseconds using FromKnownColor", sw.ElapsedMilliseconds))
And I would get mixed results. Sometimes SystemColors was quicker, but sometimes FromKnownColor was quicker, but not by much on either of them. I think it comes down to personal preference, I use FromKnownColor because intellesence picks it up for me where as it doesn't for SystemColors.
Last edited by dday9; Jun 23rd, 2014 at 10:35 AM.
Reason: speling an gramur
-
Jun 23rd, 2014, 10:45 AM
#3
Thread Starter
Addicted Member
Re: KnownColor vs SystemColors/Color?
Originally Posted by dday9
I think it comes down to personal preference, I use FromKnownColor because intellesence picks it up for me where as it doesn't for SystemColors.
That's weird intellisense works for both on my system (at least in VS2010)..
Hmmm.. I guess the SystemColors is a collections of classes, and the KnownColor is an Enum.. Ahh, so I guess the only reason (IMHO) you would use KnownColor is when you need to itterate through all colors available for instance if you want a user to select a color, otherwise you have to use reflection (as I read in some posts on other sites when people want to itterate through the systemcolors)..
But if you're using it directly in code IMHO it's nicer/shorter just to use SystemColors (or Color)..
-
Jun 23rd, 2014, 10:47 AM
#4
Re: KnownColor vs SystemColors/Color?
That's weird intellisense works for both on my system (at least in VS2010)..
It's not that it doesn't work picking up the actually colors, it just won't pick up the word SystemColors. As soon as I type in:
It picks up all the colors. I'm using VS2010 Express.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|