Laden...

[erledigt] Color Properties stimmen nicht mit RGB-Wert überein?

Erstellt von Aratar vor 13 Jahren Letzter Beitrag vor 13 Jahren 1.280 Views
A
Aratar Themenstarter:in
118 Beiträge seit 2009
vor 13 Jahren
[erledigt] Color Properties stimmen nicht mit RGB-Wert überein?

Guten Abend,

Ich hatte schon öfters folgendes Problem, dass sich zwar leicht lösen lässt, ich aber den Grund dafür nicht kenne.

Ich habe eine Farbe definiert, z.B.


Color c = Color.FromArgb(0,0,0);

Diese Farbe entspricht ja der Farbe Schwarz.

Folgende If-Bedingung fällt aber trotzdem negativ aus:


if (c == Color.Black) // -> false

Was ist der Grund für dieses Verhalten?

Mfg
Aratar

A
Aratar Themenstarter:in
118 Beiträge seit 2009
vor 13 Jahren

Hab die Antwort nun doch noch gefunden:

This structure only does comparisons with other Color structures. To compare colors based solely on their ARGB values, you should use the ToArgb method. This is because the Equals and Equality members determine equivalency using more than just the ARGB value of the colors. For example, Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not.

691 Beiträge seit 2007
vor 13 Jahren

In der MSDN steht die Erklärung:

Color.Equals Method

his structure only does comparisons with other Color structures. To compare colors based solely on their ARGB values, you should use the ToArgb method. This is because the Equals and Equality members determine equivalency using more than just the ARGB value of the colors. For example, Black and FromArgb(0,0,0) are not considered equal, since Black is a named color and FromArgb(0,0,0) is not.

mit freundlichen Grüßen,
Tomot

Projekte: www.gesellschaftsspieler-gesucht.de