views:

359

answers:

6

the form backcolor is 14221235 , but when i set the customcolor in colordialog to equal the form backcolor, it sets it to 5046311 !!! what is the problem?

this is how i am getting the background color:

get_background = Str(Abs(Form1.BackColor.ToArgb))

the reason i am turning it into a string is because i will feed it into a string which has "32498239, 234234234, 23423234, 32234432432, 423324234"

then i take this string and put it in customcolors like this. btw this piece of code works fine:

Dim numberStrings = My.Settings.mytext1.Split(","c).Select(Function(x) x.Trim())
ColorDialog1.CustomColors = numberStrings.Select(Function(x) CInt(x)).ToArray()

a user below mentioned that toargb takes into account the opacity. this is an excellent point indeed, and i want to clarify that i DO NOT need the opacity. how would i do toargb without taking into opacity?

+2  A: 

The 32-bit result from .ToArgb() contains not just the three visible color components (red, green and blue) but also the alpha component, which is essentially opacity. This is a pure guess on my part, but I think the ColorDialog is just used for picking RGB values, so when you set the color to the form's BackColor, the dialog just ignores the alpha component (or sets it to zero), which is why you end up getting a different number from the .ToArgb() method.

Note: this is just speculation on my part. It would help if you posted a code sample that demonstrates the specific problem.

MusiGenesis
this could be true. so if this is indeed the case, how do i make it work?
I__
not sure, in both numbers mentioned in the title the alpha is 00
Kip
@avrohom: I don't fully understand what your actual problem is, i.e. what isn't working. Your form's BackColor property is of the type Color, which makes the RGB components available as separate properties (e.g. form1.BackColor.R, form1.BackColor.G and form1.BackColor.B). There is a constructor for the Color type that takes R, G, and B values - try using the RGB values from the form's BackColor property to create a new Color object, and use this new Color object for your ColorDialog. This will remove the alpha component from the whole deal. Maybe that will fix whatever your problem is.
MusiGenesis
@Kip: I think you're right, so I dunno. I'm really not sure what the problem is.
MusiGenesis
+1  A: 

I don't really understand the question. You want to set the custom color dialog CustomColor property to (the form's backcolor) r + g + b components? Not sure why you would do that, you can always just get the form's backcolor, set the Alpha value to 255 and then set the result to the CustomColor property:

Color c = Color.FromArgb( 255, form1.BackColor );
myColorDlg.CustomColor = c;
Ed Swangren
this is not working unfortunately, i actually need to set a string equal to the color for example: get_background = Str(Abs(Form1.BackColor.ToArgb))
I__
A: 

Or just use form1.BackColor.ToArgb() & 0xFFFFFF (if you want the integer value).

Ron Warholic
this one is not working, it makes it equal something like this -2342340xFFFFFF
I__
This would set the alpha component to 0.
Ed Swangren
+1  A: 

this is what you want

Microsoft.VisualBasic.RGB(Me.BackColor.R, Me.BackColor.G, Me.BackColor.B).ToString
Fredou
what didn't work?
Fredou
thank you very very much
I__
welcome... and thanks for the *3 reputation, next time keep it in one question :-)
Fredou
Why the double posted answer? And why use a language-dependent function like RGB?
Adam Robinson
@Adam, it was 3 questions, seem to be merged into 1 now, deleted my other one and for the RGB, you can use visualbasic namespace in c# too
Fredou
@Adam what would be the "generic" one? color.fromargb? it doesn't convert well into int
Fredou
A: 

If you are asking for ARGB (A = Alpha) then you are asking for the opacity information. Instead you could use the R, G, B Properties of Color Independently.

Quintin Robinson
how would i set one of the custom colors in colordialog to have the same rgb?>
I__
you can construct an int with the correct byte ordering (AARRGGBB) and just falsify the AA value with 255.
Quintin Robinson
cool can you please show me this in code?>
I__
A: 

You could use Color.FromArgb(255, me.BackColor).ToArgb() in order to get the ARGB value of the same color with 100% opacity.

Adam Robinson
Error 1 Value of type 'Integer' cannot be converted to 'System.Drawing.Color'.
I__
You interpreted his answer too literally, for your needs you don't need the tailing .ToArgb(), drop it and you will be returned a color object and it should work for you.
Quintin Robinson
i tried just this and it didnt work Color.FromArgb(255, me.BackColor.ToArgb())
I__
@avrohom, That was a typo. ToArgb() should not be called on me.BackColor in this scenario.
Adam Robinson
@Adam: your top-voted question is most ironic, in this case. :)
MusiGenesis