473,785 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.DrawingC olor.ToKnowColo r method will not do this for me.

Thanks in advance for any help.

-Sam Matzen


Nov 20 '05 #1
5 29186
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/
frlrfSystemDraw ingColorClassTo KnownColorTopic .asp
So I think we can compare the argb value with the knowncolors' to know
which knowncolor matched current color.

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim kc As Color = Color.FromKnown Color(KnownColo r.Blue)
Dim cr As Color = Color.FromArgb( kc.ToArgb())
Dim c As KnownColor
For i As Integer = 1 To 137
If Color.FromKnown Color(i).ToArgb () = cr.ToArgb() Then
Debug.WriteLine (CType(i, KnownColor).ToS tring())
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.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.DrawingC olor.ToKnowColo r 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(i nt iARGBValue, out string strKnownColor)
{
Color someColor;

Array aListofKnownCol ors = Enum.GetValues( typeof(KnownCol or));
foreach (KnownColor eKnownColor in aListofKnownCol ors)
{
someColor = Color.FromKnown Color(eKnownCol or);
if (iARGBValue == someColor.ToArg b() && !someColor.IsSy stemColor)
{
strKnownColor = someColor.Name;
return true;
}
}
strKnownColor = "";
return false;
}
Thanx to Robert Hachtel (ro***********@ panoramicsci.co m) on
microsoft.publi c.dotnet.framew ork.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.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.DrawingC olor.ToKnowColo r 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.m icrosoft.com> wrote in message
news:JJ******** ******@cpmsftng xa10.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/ frlrfSystemDraw ingColorClassTo KnownColorTopic .asp
So I think we can compare the argb value with the knowncolors' to know
which knowncolor matched current color.

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim kc As Color = Color.FromKnown Color(KnownColo r.Blue)
Dim cr As Color = Color.FromArgb( kc.ToArgb())
Dim c As KnownColor
For i As Integer = 1 To 137
If Color.FromKnown Color(i).ToArgb () = cr.ToArgb() Then
Debug.WriteLine (CType(i, KnownColor).ToS tring())
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******@hotma il.com> wrote in message
news:uJ******** ******@tk2msftn gp13.phx.gbl...
Hi Samuel,

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

Array aListofKnownCol ors = Enum.GetValues( typeof(KnownCol or));
foreach (KnownColor eKnownColor in aListofKnownCol ors)
{
someColor = Color.FromKnown Color(eKnownCol or);
if (iARGBValue == someColor.ToArg b() && !someColor.IsSy stemColor)
{
strKnownColor = someColor.Name;
return true;
}
}
strKnownColor = "";
return false;
}
Thanx to Robert Hachtel (ro***********@ panoramicsci.co m) on
microsoft.publi c.dotnet.framew ork.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.co m> wrote in message
news:%2******** ********@TK2MSF TNGP12.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.DrawingC olor.ToKnowColo r 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
4843
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 some paint utility, I am having some problems with trying to compare the color of the pixel that I retrieve using Bitmap.GetPixel(...) method. My pseudo-code looks like this:...
4
2170
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 always getting the first page. Is there a way to get the name of the transfered page?
4
1614
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
1304
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
2145
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 Alternatively, is there a piece of code I can use to pass in the name of the method, so that I can copy and paste the calling code and don't have to remember to change a hard coded method name. I could code this:
4
1348
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 the file (or login, and copy the link) you can get at the file without logging in. I verified this by pulling up one of my pfds copying the url, closing down all of IE and then starting IE and putting in the url. Lo and hehold - the file is...
1
1625
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
1569
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 subform? I've not found a direct way to get that little nugget of information. Thanks for your time, David
3
2040
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
9647
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10161
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10098
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7506
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6743
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...

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.