How to do this without control?

A few months ago I wrote this code because it was the only way I could do this (by learning C #), well. How would you do that? Is the uncheckedright way to do this?

unchecked //FromArgb takes a 32 bit value, though says it signed. Which colors shouldn't be.
{
  _EditControl.BackColor = System.Drawing.Color.FromArgb((int)0xFFCCCCCC);
}
+5
source share
3 answers

You can break up the int components and use the overload FromArgb()that takes them separately:

System.Drawing.Color.FromArgb( 0xFF, 0xCC, 0xCC, 0xCC);
+2
source

It accepts a signed int b / c, this refers to the time when VB.NET had no unsigned values. Therefore, to maintain compatibility between C # and VB.NET, all BCL libraries use signed values, even if they have no logical meaning.

+6

:

public static Color ToColor(this uint argb)
{
    return Color.FromArgb(unchecked((int)argb));
}

public static Color ToColor(this int argb)
{
    return Color.FromArgb(argb);
}

:

0xff112233.ToColor(); 
0x7f112233.ToColor();

, (, 0v12345678) - .

0

All Articles