color translator give incorrect result

denesh neupane 121 Reputation points
2022-06-23T01:05:04.67+00:00

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

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
328 questions
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.
10,648 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,141 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,731 Reputation points
    2022-06-23T01:35:03.44+00:00

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

    https://learn.microsoft.com/en-us/windows/win32/gdi/colorref

    Note: this because windows is little endian

    1 person found this answer helpful.
    0 comments No comments