Results 1 to 9 of 9

Thread: color code via color control? [Resolved]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    28

    Resolved color code via color control? [Resolved]

    Ineed to make something , like the pic in the attachment , where i let the user pick his color , and once he clicks "ok" ; the color code will appear in a text box in the main form.

    Any ideas?
    Attached Images Attached Images  
    Last edited by KeyStroke; Jun 9th, 2005 at 08:11 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: color code via color control?

    Drop a ColorDialog control on to your form. Then this code will give you what you want except for the Hex number. It will use the .Color
    property which contains the Long number format of the color. You just need to convert the long into hex and display in your label or ???

    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     With ColorDialog1
    3.         .AllowFullOpen = True
    4.         .AnyColor = True
    5.         .FullOpen = True
    6.         .SolidColorOnly = False
    7.         If .ShowDialog = DialogResult.OK Then
    8.             Me.BackColor = .Color
    9.             Me.Label1.Text = Hex(.Color.ToArgb)
    10.         End If
    11.     End With
    12. End Sub
    Last edited by RobDog888; Jun 5th, 2005 at 11:38 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: color code via color control?

    Forgot to mention that you may want to prepopulate the color dialog first so the custom colors pointer will be updated to the location of the color.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    28

    Re: color code via color control?

    Great !! i have two questions though :
    - the "SolidColorOnly" doesn't seem necessary (it works without it) , why did you put it there?

    - When using your method , i get a Hex number of 8 digits whereas color codes go as long as 6 digits (Photoshop doesn't allow a hex code more than 6 digits). Any ideas on how to solve this problem?

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: color code via color control?

    The solidcoloronly = false will give the user the ability to choose any color. If you want web colors then it could be set to true. I think
    that would be part of it but then sice web safe colors are not always just solid so you may need to determine the safe colors and if a non-safe one
    is choosen then you can set it to the nearest safe color.

    I think a little research on the 8 to 6 digits will be requred since I cant really answer it 100%. I think you need to get a hex color from PS and set
    that as the start color in vb. Then you can see how it translates back to hex and see what the difference is. It may be that we are not using
    the correct method for what you need?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    28

    Re: color code via color control?

    I don't clearly understand what you mean by :
    I think you need to get a hex color from PS and set
    that as the start color in vb. Then you can see how it translates back to hex and see what the difference is.
    I'm talking about color codes like this one. The link explains it all.

    There's probably a way to convert the aRGB values into Hex. For example , my program produces "-16777216" when i chose black ; where in hex it should be "000000"

    any ideas?

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: color code via color control?

    8 digits of hex is 4 bytes. In colors, that translates to ARGB. RGB are Red Green Blue, while A is an alpha value that I don't fully understand. I believe this has to do with alpha blending which allows varying levels of transparency, but I suck as an artist, so I don't pretend to try to use alpha blending. The game gurus can certainly explain that in greater detail.

    I believe that the A from ARGB is the first two bytes, so you should be able to strip those off to get the RGB value that you want. You should be able to test that pretty easily, because a bright red would be 0xyyFF0000, or something close to that, while a bright green would be 0xyy00FF00, and a blue would be 0xyy0000FF. The yy in that case would be the alpha value, which you can ignore for 6 byte needs.

    Since the color object has a FromARGB() function, it seems like you ought to also be able to confirm this by passing the value into that function, then checking the R, G, and B properties.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2005
    Posts
    28

    Re: color code via color control?

    Shaggy Hiker , you're a genuis !!!

    I converted the aRGB value to Hex , ignored the first two digits and it shows colors properly, thanks alot guys!!

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: color code via color control? [Resolved]

    Too late. I was thinking of this last night while trying to sleep and I realized that it was the alpha channel that was creating
    the extra 2 digits.

    Glad to see that we have great members like Shaggy that are on top of things while we are off line.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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