how to convert the system drawing color to hex

denesh neupane 121 Reputation points
2022-06-20T05:48:02.993+00:00

how can i convert the system drawing color to hex ?? i tried the below listed code but it gives 00000000 always

       Color myColor = textBox26.BackColor;    
          System.ComponentModel.TypeConverter converter =  
          System.ComponentModel.TypeDescriptor.GetConverter(myColor);  
          string colorAsString = converter.ConvertToString(textBox26.BackColor);  
          int ColorValue = Color.FromName(colorAsString).ToArgb();  
         textBox26.Text= string.Format("{0:x6}", ColorValue);  
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,686 Reputation points
    2022-06-20T06:29:37.953+00:00

    For example :

         Color myColor = textBox26.BackColor;  
         int nColorWin32 = ColorTranslator.ToWin32(myColor);  
         textBox26.Text = string.Format("{0:X8}", nColorWin32);
    
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.