473,396 Members | 1,770 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,396 software developers and data experts.

Passing either RBG or HEX value to Server Control in VS.Net 2003

I've created a server control that builds a table. I've exposed a public property that can change the background color of the table. When I compile the control and try to use it in a project, I am able to change the color by using the properties menu in Visual Studio.Net 2003. The problem that I'm having is that anytime that I want to enter a HEX value (rather than selecting a color from the color picker), the HEX value is converted to RGB and never displays the correct color.

Here is the code that I use to expose the color property in the server control

Color tablebgcolor = Color.Empty
public Color TableBGColo

get{return tablebgcolor;
set{tablebgcolor = value;
I've used other server controls that will accept either a HEX value or allow you select from the color picker on the properties tab in Visual Studio. Does anyone know how this is done?
Nov 18 '05 #1
2 1449
This might get you going towards a solution. In my case I wanted to retrieve
HEX values stored as strings in a database and then assign them to a custom
class at runtime. In the following code, currentRow["BackColor"] contains a
HEX color value.

System.Web.UI.WebControls.WebColorConverter ColorToUse = new
WebColorConverter();

nextStyle.BackColor = (System.Drawing.Color)
ColorToUse.ConvertFrom(currentRow["BackColor"].ToString());

-K
"D Sheldon" <an*******@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com...
I've created a server control that builds a table. I've exposed a public property that can change the background color of the table. When I compile
the control and try to use it in a project, I am able to change the color by
using the properties menu in Visual Studio.Net 2003. The problem that I'm
having is that anytime that I want to enter a HEX value (rather than
selecting a color from the color picker), the HEX value is converted to RGB
and never displays the correct color.
Here is the code that I use to expose the color property in the server control:
Color tablebgcolor = Color.Empty;
public Color TableBGColor
{
get{return tablebgcolor;}
set{tablebgcolor = value;}
}

I've used other server controls that will accept either a HEX value or

allow you select from the color picker on the properties tab in Visual
Studio. Does anyone know how this is done?
Nov 18 '05 #2
I found the following code, which seems to be working (ie it converts the RBG into HEX, in the code), but I still can't get the Visual Studio properties window to keep the HEX value (rather than automatically converting it to RBG).

private string ColorToHtml(Color c)

string html = ""
html = c.R.ToString("X")
if (html.Length < 2) html+="0"
html += c.G.ToString("X")
if (html.Length < 4) html+="0";
html += c.B.ToString("X")
if (html.Length < 6) html+="0"
return "#" + html
At this point, I guess I should be happy that the control is working correctly, but the O.C.D. in me can't stand it when VS.Net converts to RBG.

Nov 18 '05 #3

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

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
7
by: Ken Allen | last post by:
I have a .net client/server application using remoting, and I cannot get the custom exception class to pass from the server to the client. The custom exception is derived from ApplicationException...
7
by: Cemal Karademir | last post by:
Hello, Please forgive my simple question, but i don't know the correct synatx. From the masterpage i want to put a text in an textbox and then select an item in the datagrid. I do know how to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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...
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...

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.