.NET applications frequently require converting hexadecimal color codes (like #RRGGBB) into usable Color
objects. This guide shows how to easily achieve this.
For Windows Forms or GDI applications, use the System.Drawing.Color
class:
<code class="language-csharp">Color color = ColorTranslator.FromHtml("#FFDFD991");</code>
For WPF or XAML applications, the System.Windows.Media.Color
class provides a similar function:
<code class="language-csharp">Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");</code>
In both examples, the hex code (including the # symbol representing an ARGB value) is passed as a string. The methods parse the hex code and create the appropriate Color
object, allowing seamless color integration within your .NET projects.
The above is the detailed content of How to Convert Hexadecimal Color Codes to .NET Color Objects?. For more information, please follow other related articles on the PHP Chinese website!