Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

RGB Colors

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 30 Oct 2007 17:42 GMT
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.
Armin Zingler - 30 Oct 2007 17:53 GMT
> 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
[quoted text clipped - 5 lines]
>
> How can I assign an RGB Color to a BackColor via code?

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

Armin
Eternal Snow - 31 Oct 2007 02:54 GMT
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.

> I'm using VB 2005.
>
[quoted text clipped - 12 lines]
>
> Thanks.
Jeffrey Tan[MSFT] - 31 Oct 2007 03:29 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.