473,574 Members | 2,610 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can you convert an integer into a VB.NET color?

In VB6, foreground and background colors of controls had to be assigned a
single number. If you knew the RGB values for the color, you still had to
convert them into the single number accepatable to the VB6 controls.

In VB.NET, you can't set colors that way anymore, now you have to use a
"color". There is a way to convert RGB values to a "color", using the
Color.FromARGB method. But there doens't seem to be a way to convert the old
single numbers into a "color".

In VB6, there was a method to convert rgb values into a single number, using
the RGB method. This method is still available in VB6 through the
Microsoft.Visua lBasic.Informat ion namespace. However, I have the single
numbers I used before (that were REQUIRED in VB6), I don't have separate Red,
Green, and Blue values for those numbers. Neither VB6 nor VB.NET seem to have
a method for converting a single number back to its component red, green, and
blue values!! (If there IS one, please someone tell me what it is!)

So, if there is no way to convert the single numbers back to rgb values OR
to convert them to the new "color" values, then VB.NET has changed the whole
system for assigning colors to controls, and is giving me no way to convert
the numbers that were required before into the new system. That's not very
nice!

If anyone has an answer for this, please let me know.

--
Thanks.
ro*****@hotmail .com
Jun 6 '06 #1
5 8621
The table available through MSDN link beflow 'may' help you:

http://msdn.microsoft.com/library/de...alBasicNET.asp
"Bob Homes" <ro*****@hotmai l.com.(nospam)> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
In VB6, foreground and background colors of controls had to be assigned a
single number. If you knew the RGB values for the color, you still had to
convert them into the single number accepatable to the VB6 controls.

In VB.NET, you can't set colors that way anymore, now you have to use a
"color". There is a way to convert RGB values to a "color", using the
Color.FromARGB method. But there doens't seem to be a way to convert the
old
single numbers into a "color".

In VB6, there was a method to convert rgb values into a single number,
using
the RGB method. This method is still available in VB6 through the
Microsoft.Visua lBasic.Informat ion namespace. However, I have the single
numbers I used before (that were REQUIRED in VB6), I don't have separate
Red,
Green, and Blue values for those numbers. Neither VB6 nor VB.NET seem to
have
a method for converting a single number back to its component red, green,
and
blue values!! (If there IS one, please someone tell me what it is!)

So, if there is no way to convert the single numbers back to rgb values OR
to convert them to the new "color" values, then VB.NET has changed the
whole
system for assigning colors to controls, and is giving me no way to
convert
the numbers that were required before into the new system. That's not very
nice!

If anyone has an answer for this, please let me know.

--
Thanks.
ro*****@hotmail .com

Jun 6 '06 #2
Hello Bob,

Check out the System.Drawing. ColorTranslator class. (hint: VB6 color storage
is defined by OLE).

-Boo
In VB6, foreground and background colors of controls had to be
assigned a single number. If you knew the RGB values for the color,
you still had to convert them into the single number accepatable to
the VB6 controls.

In VB.NET, you can't set colors that way anymore, now you have to use
a "color". There is a way to convert RGB values to a "color", using
the Color.FromARGB method. But there doens't seem to be a way to
convert the old single numbers into a "color".

In VB6, there was a method to convert rgb values into a single number,
using the RGB method. This method is still available in VB6 through
the Microsoft.Visua lBasic.Informat ion namespace. However, I have the
single numbers I used before (that were REQUIRED in VB6), I don't have
separate Red, Green, and Blue values for those numbers. Neither VB6
nor VB.NET seem to have a method for converting a single number back
to its component red, green, and blue values!! (If there IS one,
please someone tell me what it is!)

So, if there is no way to convert the single numbers back to rgb
values OR to convert them to the new "color" values, then VB.NET has
changed the whole system for assigning colors to controls, and is
giving me no way to convert the numbers that were required before into
the new system. That's not very nice!

If anyone has an answer for this, please let me know.

Jun 6 '06 #3
Mike, no, it really doesn't. I have a whole bunch of "strange" colors, not
just the usual 7 or 8. Thanks anyway.

ro*****@hotmail .com
"Mike McIntyre" wrote:
The table available through MSDN link beflow 'may' help you:

http://msdn.microsoft.com/library/de...alBasicNET.asp
"Bob Homes" <ro*****@hotmai l.com.(nospam)> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
In VB6, foreground and background colors of controls had to be assigned a
single number. If you knew the RGB values for the color, you still had to
convert them into the single number accepatable to the VB6 controls.

In VB.NET, you can't set colors that way anymore, now you have to use a
"color". There is a way to convert RGB values to a "color", using the
Color.FromARGB method. But there doens't seem to be a way to convert the
old
single numbers into a "color".

In VB6, there was a method to convert rgb values into a single number,
using
the RGB method. This method is still available in VB6 through the
Microsoft.Visua lBasic.Informat ion namespace. However, I have the single
numbers I used before (that were REQUIRED in VB6), I don't have separate
Red,
Green, and Blue values for those numbers. Neither VB6 nor VB.NET seem to
have
a method for converting a single number back to its component red, green,
and
blue values!! (If there IS one, please someone tell me what it is!)

So, if there is no way to convert the single numbers back to rgb values OR
to convert them to the new "color" values, then VB.NET has changed the
whole
system for assigning colors to controls, and is giving me no way to
convert
the numbers that were required before into the new system. That's not very
nice!

If anyone has an answer for this, please let me know.

--
Thanks.
ro*****@hotmail .com


Jun 6 '06 #4
On Tue, 6 Jun 2006 03:58:48 +0000 (UTC), GhostInAK
<gh*******@gmai l.com> wrote:
Hello Bob,

Check out the System.Drawing. ColorTranslator class. (hint: VB6 color storage
is defined by OLE).

-Boo
There's even a discussion in the Help file about VB6/VB2005 color
handling changes. What a novel idea.

Gene
In VB6, foreground and background colors of controls had to be
assigned a single number. If you knew the RGB values for the color,
you still had to convert them into the single number accepatable to
the VB6 controls.

In VB.NET, you can't set colors that way anymore, now you have to use
a "color". There is a way to convert RGB values to a "color", using
the Color.FromARGB method. But there doens't seem to be a way to
convert the old single numbers into a "color".

In VB6, there was a method to convert rgb values into a single number,
using the RGB method. This method is still available in VB6 through
the Microsoft.Visua lBasic.Informat ion namespace. However, I have the
single numbers I used before (that were REQUIRED in VB6), I don't have
separate Red, Green, and Blue values for those numbers. Neither VB6
nor VB.NET seem to have a method for converting a single number back
to its component red, green, and blue values!! (If there IS one,
please someone tell me what it is!)

So, if there is no way to convert the single numbers back to rgb
values OR to convert them to the new "color" values, then VB.NET has
changed the whole system for assigning colors to controls, and is
giving me no way to convert the numbers that were required before into
the new system. That's not very nice!

If anyone has an answer for this, please let me know.

Jun 6 '06 #5
=?Utf-8?B?Qm9iIEhvbWV z?= <ro*****@hotmai l.com.(nospam)> wrote in
news:4B******** *************** ***********@mic rosoft.com:
In VB6, foreground and background colors of controls had to be
assigned a single number. If you knew the RGB values for the color,
you still had to convert them into the single number accepatable to
the VB6 controls.

In VB.NET, you can't set colors that way anymore, now you have to use
a "color". There is a way to convert RGB values to a "color", using
the Color.FromARGB method. But there doens't seem to be a way to
convert the old single numbers into a "color".

In VB6, there was a method to convert rgb values into a single number,
using the RGB method. This method is still available in VB6 through
the Microsoft.Visua lBasic.Informat ion namespace. However, I have the
single numbers I used before (that were REQUIRED in VB6), I don't have
separate Red, Green, and Blue values for those numbers. Neither VB6
nor VB.NET seem to have a method for converting a single number back
to its component red, green, and blue values!! (If there IS one,
please someone tell me what it is!)

So, if there is no way to convert the single numbers back to rgb
values OR to convert them to the new "color" values, then VB.NET has
changed the whole system for assigning colors to controls, and is
giving me no way to convert the numbers that were required before into
the new system. That's not very nice!

If anyone has an answer for this, please let me know.


Color.FromARGB( integer)

It is overloaded. See the msdn help for color.fromArgb.

to get the R, G and B from a color just use

dim r as byte = myColor.R
etc.

Colors are just int32s. ARGB = byte order.
So you can split with bitwise operators:

here's some general messing about:

Dim c As Color = Color.Chocolate
Debug.WriteLine (Hex(c.ToArgb))
' outputs: FFD2691E
Dim red As Byte = c.R
Dim green As Byte = c.G
Dim blue As Byte = c.B
Dim c2 As Color = Color.FromArgb( &HFFD2691E)
Debug.WriteLine (Hex(c2.ToArgb) )
' outputs: FFD2691E
Dim red2 As Byte = &HD2
Dim green2 As Byte = &H69
Dim blue2 As Byte = &H1E
Dim c3 As Color = Color.FromArgb( red2, green2, blue2)
Debug.WriteLine (Hex(c3.ToArgb) )
' outputs: FFD2691E
' do it manually:
Dim color4int As Integer = &HFFD2691E
Dim R4 As Byte = (color4int >> 16) And &HFF
Dim G4 As Byte = (color4int >> 8) And &HFF
Dim b4 As Byte = (color4int And &HFF)
Debug.WriteLine (String.Concat( "red: ", Hex(R4), ", green : ", Hex(G4), ",
blue: ", Hex(b4)))
' outputs: red: D2, green : 69, blue: 1E
' reassemble:
Dim color5int As Integer = (CInt(R4) << 16) Or (CInt(G4) << 8) Or b4
Dim color5 As Color = Color.FromArgb( color5int)
Debug.WriteLine (Hex(color5.ToA rgb))
' outputs D2691E - no alpha!
' use another override to supply the alpha for a base color:
Dim color6 As Color = Color.FromArgb( &HFF, Color.FromArgb( color5int))
Debug.WriteLine (Hex(color6.ToA rgb))
' outputs FFD2691E
' or you could have added it bitwise:
Dim color7int As Integer = (&HFF << 24) Or (CInt(R4) << 16) Or (CInt(G4)
<< 8) Or b4
Dim color7 As Color = Color.FromArgb( color7int)
Debug.WriteLine (Hex(color6.ToA rgb))
Always check the overload list for a method. It pops up in intellisense:

after typing this:
dim c as color = color.fromARGB(

intellisense pops up
"1 of 4 FromARGB(argb as integer) as System.Drawing. Color
argb = A value specifying the 32 bit color value"

and you can press the up and down arrows to see the other overloads.

For more info on an overload, look in the help...
Jun 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
3865
by: Ste | last post by:
Hi, I have a dump with a table with this field: "hdstart" integer which contains integer like 1042758000 1028152800 etc etc How can I convert it to a SQL Server DateTime field? Thank in advance and sorry for my bad english...
3
33649
by: glenn h | last post by:
I have i time in Integer = 37825 , how can I convert it in C# to Timeformat = 10:30:25 Glenn
7
13869
by: henrytcy | last post by:
Hi, How can I convert integer, for example 12113, to char array but without specify an array size in C programming? Thanks!
5
1547
by: VB Programmer | last post by:
How do I convert the following to a HEX code I can use in HTML documents? 1. 2. Aqua FYI: When I print the session variable I'm storing this color in (in the Immediate window) I get this: ? session("MyBackgroundColor") "Color " {String} String: "Color "
2
5078
by: Tom | last post by:
I need to convert an integer to a GUID consisting only of capital letters and numbers. I also need to be able to convert it back again. I would prefer it was somewhat difficult to determine how to convert it back. What do I do? :-) Regards
2
15191
karthickbabu
by: karthickbabu | last post by:
Hi In my application i want to convert integer to decimal. I get a input and using convert function to convert into decimal. But it shows as it self. My code like as below, Is any wrong in my code dim input as long // I declare as long dim decimaloutput as decimal decimaloutput = Convert.ToDecimal(input) label1.text =...
4
2251
by: mthread | last post by:
Hi, I would like to know the method to convert integer to string. Thanx in advance.
6
10590
by: ngajay | last post by:
Please tell me... how to convert integer to hex in little endian format ? example : i'm input int = 9995 then the output in Array String is
2
2431
by: pantherxin | last post by:
Writing program to calculate cir., area, etc. of circle. Radius is input as integer; how to convert integer to proceed with calculations?
0
7814
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7737
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8075
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8253
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8109
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6471
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5632
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2253
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.