473,503 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Color.DarkMagenta to #hexcolor

I have a color System.Drawing.Color.DarkMagenta
I would like to output it to the browser as its hex color(not sure what it
is) #993484

This seems like it should work but it isn't.
------------------------------------------------------------------
System.Drawing.Color c = System.Drawing.Color.DarkMagenta;
string HtmlColor = System.Drawing.Color.ToHtml(c);

Response.Write(HtmlColor); //Outputing "DarkMagenta"
------------------------------------------------------------------

Shouldn't the ToHtml() method give me a hex string representation instead of
the color name?
Anyone got any ideas?

--
Ron Vecchi
Nov 18 '05 #1
2 1041
Use function
Function convertToHexColor(ByVal c As Color) As String
Return "#" + c.ToArgb().ToString("x").Substring(2)
End Function

HTH
-Sushila

"Ron Vecchi" <rv*****@xilehdvecchi.com> wrote in message news:#s**************@TK2MSFTNGP12.phx.gbl...
I have a color System.Drawing.Color.DarkMagenta
I would like to output it to the browser as its hex color(not sure what it
is) #993484

This seems like it should work but it isn't.
------------------------------------------------------------------
System.Drawing.Color c = System.Drawing.Color.DarkMagenta;
string HtmlColor = System.Drawing.Color.ToHtml(c);

Response.Write(HtmlColor); //Outputing "DarkMagenta"
------------------------------------------------------------------

Shouldn't the ToHtml() method give me a hex string representation instead of
the color name?
Anyone got any ideas?

--
Ron Vecchi



Nov 18 '05 #2
I think if you created the Color from a KnownColor, it will always return
you the literal. But it's easy enough to produce the results you want

(sorry, it's VB);

Dim c As System.Drawing.Color = System.Drawing.Color.DarkMagenta
Dim HtmlColor As String = "#"
HtmlColor &= Right("00" & Hex(c.R), 2)
HtmlColor &= Right("00" & Hex(c.G), 2)
HtmlColor &= Right("00" & Hex(c.B), 2)

"Ron Vecchi" <rv*****@xilehdvecchi.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I have a color System.Drawing.Color.DarkMagenta
I would like to output it to the browser as its hex color(not sure what it
is) #993484

This seems like it should work but it isn't.
------------------------------------------------------------------
System.Drawing.Color c = System.Drawing.Color.DarkMagenta;
string HtmlColor = System.Drawing.Color.ToHtml(c);

Response.Write(HtmlColor); //Outputing "DarkMagenta"
------------------------------------------------------------------

Shouldn't the ToHtml() method give me a hex string representation instead of the color name?
Anyone got any ideas?

--
Ron Vecchi

Nov 18 '05 #3

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

Similar topics

4
5356
by: dan glenn | last post by:
(PHP4.3.4, GD2) How can I save a PNG using GD2 and insure that it saves as a palette-based (8-bit, 256-color) single-color transparancy?? Saving this way, I could be sure that an image loaded from...
6
4092
by: me | last post by:
good day, i found this message: and i want to know more about it too. ========================================== Hey all, example:...
6
8491
by: rzed | last post by:
I'm using PIL to generate some images which may be rotated at the user's option. When they are rotated, the original image is cropped in the new image (which is fine), and the corners are black...
3
5047
by: Richard A. DeVenezia | last post by:
I hope this is the end of my present 'discovery' phase. I've learned alot about JavaScript in a short time and my head hurts. The following is what came out of all my questions and all the...
5
3456
by: Chris Beall | last post by:
I'm displaying an image that is also a link against a black background. In Netscape 7.1, the current background color is displayed as a horizontal bar below the image. This allows :hover effects...
4
19881
by: bart plessers | last post by:
Hello, I am making a website where the user can choose a 'skin'. This works with asp en stylesheets. In the stylesheet, a number of tags are (re)defined. The main idea is to have a limited...
0
386
by: Supra | last post by:
: error BC30311: Value of type 'System.Drawing.Color' cannot be converted to 'Integer'. Function doColor(ByVal rtb As RichTextBox, ByVal a As String, Optional ByVal f As Integer = 0, Optional...
19
5753
by: MLH | last post by:
I'm wondering if the BackColor property values for the colors built-in to A97 come from some internationally recognized standard. I have a list of a hundred or so colors with hex values and I'm...
59
6867
by: pamelafluente | last post by:
Hi, If I have: <div style="background:anyColorHere"Hi </div> where anyColorHere is any hex string that represent a valid color. How can I invert that background color "anyColorHere" ? Can...
0
7192
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,...
0
7261
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,...
1
6974
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
5559
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,...
1
4991
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
4665
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...
0
3158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.