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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikysaran
    New Member
    • Nov 2006
    • 14

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

    This is my code bellow:-

    Code:
    private void _tabControl1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
            {
                Font f;
                Brush backBrush;
                Brush foreBrush;
    
                if (e.Index == this._tabControl1.SelectedIndex)
                {
                    f = new Font(e.Font, FontStyle.Bold | FontStyle.Regular);
                    backBrush = new System.Drawing.Drawing2D.LinearGradientBrush(e.Bounds, Color.Gainsboro, Color.Gainsboro, System.Drawing.Drawing2D.LinearGradientMode.Vertical);
                    foreBrush = Brushes.Black;
                }
                else
                {
                    f = e.Font;
                    backBrush = new SolidBrush(e.BackColor);
                    foreBrush = new SolidBrush(e.ForeColor);
                }
    
                string tabName = this._tabControl1.TabPages[e.Index].Text;
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                e.Graphics.FillRectangle(backBrush, e.Bounds);
                Rectangle r = e.Bounds;
                r = new Rectangle(r.X, r.Y + 3, r.Width, r.Height - 3);
                e.Graphics.DrawString(tabName, f, foreBrush, r, sf);
                sf.Dispose();
                if (e.Index == this._tabControl1.SelectedIndex)
                {
                    f.Dispose();
                    backBrush.Dispose();
                }
                else
                {
                    backBrush.Dispose();
                    foreBrush.Dispose();
                }
    		}
    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 Files
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    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.

    Comment

    • vikysaran
      New Member
      • Nov 2006
      • 14

      #3
      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-

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        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.

        Comment

        Working...