473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Argb Color to Know Color Name

Hi NG,

I have an Argb color stored in a database as a 32 bit integer.

If this color is a KnownColor, is there any way I can get the known color
name so I can display the known color name on the form and in my reports?

The System.DrawingColor.ToKnowColor method will not do this for me.

Thanks in advance for any help.

-Sam Matzen


Nov 20 '05 #1
5 29121
Hi Samuel,

As the document said,
Return Value
An element of the KnownColor enumeration, if the Color structure is created
from a pre-defined color by using either the FromName method or the
FromKnownColor method; otherwise, zero.

Remarks
A pre-defined color is also called a known color and is represented by an
element of the KnownColor enumeration. When the ToKnownColor method is
applied to a Color structure that is created by using the FromArgb method,
the ToKnownColor method returns zero, even if the ARGB value matches the
ARGB value of a pre-defined color. The ToKnownColor method also returns
zero when it is applied to a Color structure that is created by using the
FromName method with an invalid string name.

[link]
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemDrawingColorClassToKnownColorTopic.asp
So I think we can compare the argb value with the knowncolors' to know
which knowncolor matched current color.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim kc As Color = Color.FromKnownColor(KnownColor.Blue)
Dim cr As Color = Color.FromArgb(kc.ToArgb())
Dim c As KnownColor
For i As Integer = 1 To 137
If Color.FromKnownColor(i).ToArgb() = cr.ToArgb() Then
Debug.WriteLine(CType(i, KnownColor).ToString())
End If
Next
End Sub

So you will use the method very frequently, we can build a hashtable with
argb to knowncolor name mapping, so that the performance will be better.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Hi Samuel,

I am afraid I dont know how to solve this problem, but I can tell you why
the ToKnownColor doesnt work. It does this due to the following reason
Return Value
An element of the KnownColor enumeration, if the Color structure is created
from a pre-defined color by using either the FromName method or the
FromKnownColor method; otherwise, zero.

Remarks
A pre-defined color is also called a known color and is represented by an
element of the KnownColor enumeration. When the ToKnownColor method is
applied to a Color structure that is created by using the FromArgb method,
the ToKnownColor method returns zero, even if the ARGB value matches the
ARGB value of a pre-defined color. The ToKnownColor method also returns zero
when it is applied to a Color structure that is created by using the
FromName method with an invalid string name.

got from MSDN
http://msdn.microsoft.com/library/de...colortopic.asp

rawCoder

"Samuel L Matzen" <sm*****@slm.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi NG,

I have an Argb color stored in a database as a 32 bit integer.

If this color is a KnownColor, is there any way I can get the known color
name so I can display the known color name on the form and in my reports?

The System.DrawingColor.ToKnowColor method will not do this for me.

Thanks in advance for any help.

-Sam Matzen

Nov 20 '05 #3
Hi Samuel,

While searchig your problem on newsgroups .. i found a simple (not best)
solution
public bool GetKnownColor(int iARGBValue, out string strKnownColor)
{
Color someColor;

Array aListofKnownColors = Enum.GetValues(typeof(KnownColor));
foreach (KnownColor eKnownColor in aListofKnownColors)
{
someColor = Color.FromKnownColor(eKnownColor);
if (iARGBValue == someColor.ToArgb() && !someColor.IsSystemColor)
{
strKnownColor = someColor.Name;
return true;
}
}
strKnownColor = "";
return false;
}
Thanx to Robert Hachtel (ro***********@panoramicsci.com) on
microsoft.public.dotnet.framework.drawing who posted this on 2002-02-20
11:49:37 PST in response to How can find if a given ARGB value is a known
color?

btw .. the hashtable thing that Peter Huang recommended is the ideal thing.

I hope u will take time to convert it to VB ... and that wont be much of a
problem ...

Thank You,
rawCoder


"Samuel L Matzen" <sm*****@slm.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi NG,

I have an Argb color stored in a database as a 32 bit integer.

If this color is a KnownColor, is there any way I can get the known color
name so I can display the known color name on the form and in my reports?

The System.DrawingColor.ToKnowColor method will not do this for me.

Thanks in advance for any help.

-Sam Matzen

Nov 20 '05 #4
Peter,

Thanks, that is what I was looking for.

-Sam Matzen
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:JJ**************@cpmsftngxa10.phx.gbl...
Hi Samuel,

As the document said,
Return Value
An element of the KnownColor enumeration, if the Color structure is created from a pre-defined color by using either the FromName method or the
FromKnownColor method; otherwise, zero.

Remarks
A pre-defined color is also called a known color and is represented by an
element of the KnownColor enumeration. When the ToKnownColor method is
applied to a Color structure that is created by using the FromArgb method,
the ToKnownColor method returns zero, even if the ARGB value matches the
ARGB value of a pre-defined color. The ToKnownColor method also returns
zero when it is applied to a Color structure that is created by using the
FromName method with an invalid string name.

[link]
http://msdn.microsoft.com/library/de...us/cpref/html/ frlrfSystemDrawingColorClassToKnownColorTopic.asp
So I think we can compare the argb value with the knowncolors' to know
which knowncolor matched current color.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim kc As Color = Color.FromKnownColor(KnownColor.Blue)
Dim cr As Color = Color.FromArgb(kc.ToArgb())
Dim c As KnownColor
For i As Integer = 1 To 137
If Color.FromKnownColor(i).ToArgb() = cr.ToArgb() Then
Debug.WriteLine(CType(i, KnownColor).ToString())
End If
Next
End Sub

So you will use the method very frequently, we can build a hashtable with
argb to knowncolor name mapping, so that the performance will be better.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #5
rawCoder,

Thanks for the research, that is what I was looking for.

-Sam Matzen
"rawCoder" <ra******@hotmail.com> wrote in message
news:uJ**************@tk2msftngp13.phx.gbl...
Hi Samuel,

While searchig your problem on newsgroups .. i found a simple (not best)
solution
public bool GetKnownColor(int iARGBValue, out string strKnownColor)
{
Color someColor;

Array aListofKnownColors = Enum.GetValues(typeof(KnownColor));
foreach (KnownColor eKnownColor in aListofKnownColors)
{
someColor = Color.FromKnownColor(eKnownColor);
if (iARGBValue == someColor.ToArgb() && !someColor.IsSystemColor)
{
strKnownColor = someColor.Name;
return true;
}
}
strKnownColor = "";
return false;
}
Thanx to Robert Hachtel (ro***********@panoramicsci.com) on
microsoft.public.dotnet.framework.drawing who posted this on 2002-02-20
11:49:37 PST in response to How can find if a given ARGB value is a known
color?

btw .. the hashtable thing that Peter Huang recommended is the ideal thing.
I hope u will take time to convert it to VB ... and that wont be much of a
problem ...

Thank You,
rawCoder


"Samuel L Matzen" <sm*****@slm.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi NG,

I have an Argb color stored in a database as a 32 bit integer.

If this color is a KnownColor, is there any way I can get the known color name so I can display the known color name on the form and in my reports?
The System.DrawingColor.ToKnowColor method will not do this for me.

Thanks in advance for any help.

-Sam Matzen


Nov 20 '05 #6

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

Similar topics

4
by: Sami | last post by:
Hello, I just started out with Windows.Forms and was going through the MS tutorials. In the tutorial where you can create a non-rectangular shaped window by using your own window painted with...
4
by: Manuel Lopez | last post by:
Hello, I need to know on evry request the page name, my problem is when use the method server.transfer, i always get the name of the calling page. I use context.Current.Request.Url, but I am...
4
by: Angel Mateos | last post by:
Is posible something like this? public Class Class1 property readonly InstanceName get return me.InstanceName endget end property end class
2
by: pipehappy | last post by:
Hello: Is it possible for an instance know its name used by other part of program. I mean like this: class test: def __init__(self): pass when some one writes
4
by: ssg31415926 | last post by:
I want to write a logging method. I want it to log the name of the calling class and method. Is there any way to do this? I presume it'll use Reflection but it's not an area I've used much.a ...
4
by: Mufasa | last post by:
I have a website where there is a login screen on it. All works fine. As part of the website I have links to some pdfs, htmls, jpgs, and assorted other stuff. I have found if you know the name of...
1
by: Zach | last post by:
Adding a custom color in color dialog box: How do you do this? I did look through MSDN but could not find the answer. Zach.
1
by: Dave | last post by:
Hello, I know that I can use the Parent property to get the name of the form that a subform is on, but what if I need the name of the subform/ subreport "box" on that form that contains my...
3
by: Sopheap Panha | last post by:
Could you give me the color and color name in System.Drawing.Color of .NET Framework? thank for helping.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.