RGB Colors

G

Guest

I'm using VB 2005.

When I select a color from the properties window for a control, it returns
an RGB color code (255,255,255). Now, when I attempt to assign a color in
code it is done using the COLOR.COLOROPTION value. How can I take an RGB
color set in the properties window and assign it via code. For example, I
have a control who's color is (192,255,192). I want to be able to also assign
this exact same color via code using the ControlName.BackColor property. I
tried doing ControlName.BackColor = RGB(192,255,192), but I get a message
stating "Value of Type Integer cannot be converted to System.Drawing.Color".

How can I assign an RGB Color to a BackColor via code?

Thanks.
 
A

Armin Zingler

Greg said:
I'm using VB 2005.

When I select a color from the properties window for a control, it
returns an RGB color code (255,255,255). Now, when I attempt to
assign a color in code it is done using the COLOR.COLOROPTION value.

I don't know "COLOROPTION". Where is it declared?
How can I take an RGB color set in the properties window and assign
it via code. For example, I have a control who's color is
(192,255,192). I want to be able to also assign this exact same
color via code using the ControlName.BackColor property. I tried
doing ControlName.BackColor = RGB(192,255,192), but I get a message
stating "Value of Type Integer cannot be converted to
System.Drawing.Color".

How can I assign an RGB Color to a BackColor via code?

ControlName.BackColor = Color.FromArgb(192,255,192)


Armin
 
E

Eternal Snow

I guess you wanna just make your program to fit different themes
automatically.

I have a stupid way to deal with that.
First, build a dictinary(of SomeRGBValue, COLOROPTION) by your code, using
enumeration e.g.
And you can get the COLOROPTION while you want to.
 
J

Jeffrey Tan[MSFT]

Hi Greg,

Armin has provided the correct solution to you. Control.BackColor property
expects an object of type "System.Drawing.Color". You may use
Color.FromArgb() method to convert numeric RGB values to the
System.Drawing.Color object.

Note: the "RGB()" function you used in the VB2005 is a legacy VB function,
which convert the RGB values into an integer value, instead of the
System.Drawing.Color type object. So the VB2005 compiler will emit the
error message: "Value of Type Integer cannot be converted to
System.Drawing.Color". See the reference below:
http://msdn2.microsoft.com/en-us/library/zc1dyw8b(VS.80).aspx

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top