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?
Printable View
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?
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With ColorDialog1 .AllowFullOpen = True .AnyColor = True .FullOpen = True .SolidColorOnly = False If .ShowDialog = DialogResult.OK Then Me.BackColor = .Color Me.Label1.Text = Hex(.Color.ToArgb) End If End With End Sub
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.
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?
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?
I don't clearly understand what you mean by :I'm talking about color codes like this one. The link explains it all.Quote:
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.
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?
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.
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!!
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. :thumb: