|
-
Jul 7th, 2004, 07:16 PM
#1
Thread Starter
Member
Colors....
Does anyone know the names of the default colors? The blue and the default form color?
I'm use color for my labels to indicate which label a user clicked, but if they click another one I want the color to return to what it was (standard windows). When I do;
Label1.Backcolor.name
I get 'control' as answer, and you can't set;
Label1.Backcolor.control
I'm using Label1.Backcolor = AnotherLabel.Backcolor right now, but just would like to know the color names.
So if anyone knows...
-
Jul 7th, 2004, 07:53 PM
#2
Sleep mode
You can find default colors in SystemColors class .
-
Jul 7th, 2004, 08:11 PM
#3
PowerPoster
Hi,
One way of finding out is to get the RGB numbers from a standard object, something like
VB Code:
Public iColR, iColG, iColB As Integer
(Then in the form load event)
iColR = Me.BackColor.R
iColG = Me.BackColor.G
iColB = Me.BackColor.B
stores the values for each of the Red, Green and Blue components of the form backcolor.
You can then use those values to set the backcolor of any other object. e.g.
VB Code:
frm2.BackColor=Color.FromArgb(iColR, iColG, iColB)
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 7th, 2004, 11:09 PM
#4
See that? Our taxes at work.
-
Jul 8th, 2004, 04:21 AM
#5
PowerPoster
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 8th, 2004, 04:24 AM
#6
Originally posted by taxes
Not quite sure what you mean
Taxes at work? Never heard the phrase?
-
Jul 8th, 2004, 04:38 AM
#7
Thread Starter
Member
Taxes, your solution is an option, but Pirate's solution works too;
Label1.Backcolor = System.Drawing.SystemColors.Control
Now is there anyone who can make a loop that 'walks' through the colors in system.drawing.systemcolors as I haven't found the blue color yet. Or through Backcolor.[a certain color].
Testing application, changing colorname, rerun application is time consuming... 
I tried something like;
Dim a as color
for each a in system.drawing.systemcolors
label1.backcolor = a
next
But that doesn't and I didn't expect it an systemcolors isn't a collection as far as I understand it, but now clue how to 'walk through' the properties.
-
Jul 8th, 2004, 05:01 AM
#8
PowerPoster
Hi,
Your original post asked how you could reset a textbox backcolor after having changed it.
I have shown you EXACTLY how to do that.
Store the RGB values in the MouseEnter event and restore them in the MouseLeave.
Alternative in design time find out the required RGB values and then simply use those values in the MouseLeave event.
You do not need to know the NAME of the colour.
Last edited by taxes; Jul 8th, 2004 at 05:04 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 8th, 2004, 05:06 AM
#9
PowerPoster
Originally posted by mendhak
Taxes at work? Never heard the phrase?
AHHHHH. But my job is FIGHTING the tax man
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 8th, 2004, 10:16 AM
#10
Sleep mode
How about much easier solution ?
VB Code:
Private c1 As Color
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'store initial color
Me.c1 = Me.BackColor
End Sub
'Example
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'change to new color
Me.BackColor = Color.Black
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'set back old color
Me.BackColor = c1
End Sub
-
Jul 8th, 2004, 11:51 AM
#11
Thread Starter
Member
Originally posted by taxes
Hi,
Your original post asked how you could reset a textbox backcolor after having changed it.
I have shown you EXACTLY how to do that.
[clipped]
You do not need to know the NAME of the colour.
Uhm,
1 - I'm talking about a label, not a textbox
2 - I ask "Does anyone know the names of the default colors?", your answer does not cover that.
3 - In your original message you take the form color, if I startup using a different color for that, my label won't change back to the color it had
If you reread my post I already give a solution to my own problem, but ask for the names of the colors because I rather solve it like that, so yes, I _do_ need to know the name of the color, that is what I'm asking. So the use of 'EXACTLY' isn't really in it's right place, certainly not when you answer a question that hasn't been asked.
Don't get me wrong I really appreciate the help, just the caps ticked me off a bit.
But your solution (and my solution and Pirate's second solution) all assume the label has the default color on startup, I don't want to change A to B and back to A, I want to switch from B to windows default color.
Assuming things makes sloppy code, so I can't assume that the form loads with a specific color (or in my case a label or whatever) but returning it to a certain color name is foolproof.
* keeps on looking for the color names *
-
Jul 8th, 2004, 12:11 PM
#12
Sleep mode
Here you go , this lists all colors in the .NET Framework .
VB Code:
Dim kn As KnownColor
For kn = KnownColor.AliceBlue To KnownColor.YellowGreen Step kn + 1
Me.listBox1.Items.Add(kn.ToString()) ' or you can iterate any other control
Next
-
Jul 8th, 2004, 01:22 PM
#13
Thread Starter
Member
Thanks a lot for the code Pirate 
Changed it to this;
VB Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim kn As KnownColor
Static Dim i As Integer
kn = KnownColor.ActiveBorder
kn = kn + i
i = i + 1
Label1.Text = kn.ToString
Label2.BackColor = Color.FromKnownColor(kn)
End Sub
Starting at 'ActiveBorder' instead of 'AliceBlue' adds some more colors. Starting from 'AliceBlue' does not contain the colors I'm looking for, starting from 'ActiveBorder' does and it seems the 'name' of the color stays as I got it before from Pirate's post about systemcolors class;
System.Drawing.SystemColors.Control
If someone somehow changes their standard system colors this will be messed up I think, but I'm done looking at this, can't spend too much time on it
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
|