color translator give incorrect result

denesh neupane 121 Reputation points

i tried to translate the textbox back color to hex code but it gives incorrect result. how can i get a correct result please help!!!!

Color myColor2 = textBox27.BackColor;
int nColorWin2 = ColorTranslator.ToWin32(myColor2);
textBox27.Text = string.Format("{0:X6}", nColorWin2);

when the background color is red it gives 0000ff and when it is blue it gives ff0000

A cross-platform toolchain for developing, building, running, and publishing .NET applications.
315 questions
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.
9,981 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,101 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce ( 52,831 Reputation points

    If you check the docs, those are the correct values.

    Note: this because windows is little endian

    1 person found this answer helpful.
    0 comments No comments