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
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.
In der MSDN steht die Erklärung:
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