Results 1 to 13 of 13

Thread: Colors....

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37

    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...

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You can find default colors in SystemColors class .

  3. #3
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Hi,

    One way of finding out is to get the RGB numbers from a standard object, something like

    VB Code:
    1. Public iColR, iColG, iColB As Integer
    2.  
    3. (Then in the form load event)
    4.         iColR = Me.BackColor.R
    5.         iColG = Me.BackColor.G
    6.         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:
    1. 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.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    See that? Our taxes at work.

  5. #5
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    Originally posted by mendhak
    See that? Our taxes at work.
    Not quite sure what you mean

    If you like it - thanks.

    If you don't -- then suggest something better

    There must be some way of getting the color.name out of this, but I haven't found it yet.
    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.

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Originally posted by taxes
    Not quite sure what you mean
    Taxes at work? Never heard the phrase?

  7. #7

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    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.

  8. #8
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949
    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.

  10. #10
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    How about much easier solution ?

    VB Code:
    1. Private c1 As Color
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         'store initial color
    5.         Me.c1 = Me.BackColor
    6.     End Sub
    7.  
    8.  
    9. 'Example
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         'change to new color
    12.         Me.BackColor = Color.Black
    13.     End Sub
    14.  
    15.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    16.         'set back old color
    17.         Me.BackColor = c1
    18.     End Sub

  11. #11

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    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 *

  12. #12
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Here you go , this lists all colors in the .NET Framework .
    VB Code:
    1. Dim kn As KnownColor
    2. For kn = KnownColor.AliceBlue  To KnownColor.YellowGreen Step kn + 1
    3. Me.listBox1.Items.Add(kn.ToString()) ' or you can iterate any other control
    4. Next

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    The Netherlands
    Posts
    37
    Thanks a lot for the code Pirate

    Changed it to this;

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.  
    3.    Dim kn As KnownColor
    4.    Static Dim i As Integer
    5.  
    6.    kn = KnownColor.ActiveBorder
    7.    kn = kn + i
    8.    i = i + 1
    9.  
    10.    Label1.Text = kn.ToString  
    11.    Label2.BackColor = Color.FromKnownColor(kn)
    12.  
    13. 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
  •  



Click Here to Expand Forum to Full Width