473,396 Members | 1,810 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.

C# App: How to convert Color name to Hexadecimal code

vikysaran
This is my code bellow:-

Expand|Select|Wrap|Line Numbers
  1. private void _tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
  2.         {
  3.             Font f;
  4.             Brush backBrush;
  5.             Brush foreBrush;
  6.  
  7.             if (e.Index == this._tabControl1.SelectedIndex)
  8.             {
  9.                 f = new Font(e.Font, FontStyle.Bold | FontStyle.Regular);
  10.                 backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Gainsboro, Color.Gainsboro, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
  11.                 foreBrush = Brushes.Black;
  12.             }
  13.             else
  14.             {
  15.                 f = e.Font;
  16.                 backBrush = new SolidBrush(e.BackColor);
  17.                 foreBrush = new SolidBrush(e.ForeColor);
  18.             }
  19.  
  20.             string tabName = this._tabControl1.TabPages[e.Index].Text;
  21.             StringFormat sf = new StringFormat();
  22.             sf.Alignment = StringAlignment.Center;
  23.             e.Graphics.FillRectangle(backBrush, e.Bounds);
  24.             Rectangle r = e.Bounds;
  25.             r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
  26.             e.Graphics.DrawString(tabName, f, foreBrush, r, sf);
  27.             sf.Dispose();
  28.             if (e.Index == this._tabControl1.SelectedIndex)
  29.             {
  30.                 f.Dispose();
  31.                 backBrush.Dispose();
  32.             }
  33.             else
  34.             {
  35.                 backBrush.Dispose();
  36.                 foreBrush.Dispose();
  37.             }
  38.         }
This is a code of coloring Tab from my window application. And I want the exact color Mercury (E6E6E6 or 230, 230, 230) of tabs . I'm unable to do that. Help me out ASAP. Also check the attachment and let me know if you can change the back color also to Tab color.
Attached Images
File Type: jpg 12.jpg (6.9 KB, 432 views)
Dec 12 '07 #1
3 10322
Plater
7,872 Expert 4TB
What exactly do you want?
The Color class has properties that allow you to get the RGB values from it.
They are sneakily named .R, .G, .B
There are your 3 integer values.
You can also create a Color object with Color.FromArgb(R,G,B). Allowing you to create a color from three values.
The .ToString() for integer values has an overload that lets you specify .ToString("X") which will print the number as a HEX value.

Please use MSDN for these VERY simple answers.
Dec 12 '07 #2
Thanx Mr. paltter,
I'm just a beginner in c#
your code Color.FromArgb(230, 230, 230) worked great.
Let me know if i can put image in tabs. I'm attaching screenshot (made by a graphic designer) that what want exactly.

Also i want to color the Backgroud of Tabs also which is taking default window color right now. Click here for screenshot.
Thanx

Existing-



Newer-

Dec 14 '07 #3
Plater
7,872 Expert 4TB
Yeah, I asked that very same question about the tab-bar background area.
I didn't get very far.
I *THINK* you can do it with the owner-draw stuff, but creating the tabs were not easy.
Other then that I don't really know.
Dec 14 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
2
by: Yosh | last post by:
Morning! I am developing an winform application in c#. I have an app.config file that contains an entry with a Url address assigned to it. When I run my application I get the following error: ...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
9
by: FalkoG | last post by:
Hello colleague I want to convert a floating number for example 5236.9856982 to a hexadecimal number. I'd tried several things but my problem is to convert the position after decimal point. I...
6
by: MrKrich | last post by:
I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal.
13
by: muss | last post by:
how to convert decimal number in a hexadecimal number using C? Please help me. Thanks.
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
1
mahet
by: mahet | last post by:
Anders Jansson was a guest here, and he was having problem: When I try to build the web, this error is displayed: ---> Error 5 Unable to convert input xml file content to a DataSet. Invalid...
6
by: sweeet_addiction16 | last post by:
hello Im writin a code in c... can sum1 pls help me out in writing a c code to convert decimalnumber to hexadecimal number.The hexadecimal number generated has to be an unsigned long.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
0
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
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.