How to create a System.Drawing.Color from its hexadecimal RGB string?

前端 未结 6 1535
-上瘾入骨i
-上瘾入骨i 2020-12-30 18:37

I want to create a System.Drawing.Color from a value like #FF00FF or FF00FF without needing to write code for that. There is any .NET

6条回答
  •  孤独总比滥情好
    2020-12-30 18:37

    It is rather easy when you use the Convert-Class. The ToInt32 function has an overload with a second parameter which represents the base the string is in.

    using System.Drawing
    
    Color yourColor = Color.FromARGB(Convert.ToInt32("FF00FF", 16));
    

提交回复
热议问题