how to convert the system drawing color to hex

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

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);  
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,918 questions
No comments
{count} votes

Accepted answer
  1. answered 2022-06-20T06:29:37.953+00:00
    Castorix31 65,246 Reputation points

    For example :

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

0 additional answers

Sort by: Most helpful