Windows Develop Bookmark and Share   
 index > Windows Forms General > Comparing 2 colors
 

Comparing 2 colors

Hi,

When I compare 2 colors like c1 == c2, it returns true, but when I do the same in a ShouldSerializePropertyName method, it doesn't work, which means it's not true then?

When I compare the components separately in the a ShouldSerializePropertyName method, it works. So any insights on the c1 == c2 issue?




Thanks,
Aw
Joan Venge  Sunday, March 02, 2008 1:19 PM

Hi,

Couldyou postsome code of your comparing logic? In my side, I just test with thefollowing code, and it works.

Code Snippet

TestControl : Control {

private string test;

public string Test

{

get { return test; }

set { test = value; }

}

private bool ShouldSerializeTest()

{

Color c1 = Color.Red;

Color c2 = Color.Red;

bool result = c1 == c2;

MessageBox.Show(result.ToString()); //shows "true"

return result;

}

}

Zhi-Xin Ye  Friday, March 07, 2008 3:51 AM
Any ideas?




Thanks,
Aw
Joan Venge  Monday, March 03, 2008 7:22 PM

Hi,

Couldyou postsome code of your comparing logic? In my side, I just test with thefollowing code, and it works.

Code Snippet

TestControl : Control {

private string test;

public string Test

{

get { return test; }

set { test = value; }

}

private bool ShouldSerializeTest()

{

Color c1 = Color.Red;

Color c2 = Color.Red;

bool result = c1 == c2;

MessageBox.Show(result.ToString()); //shows "true"

return result;

}

}

Zhi-Xin Ye  Friday, March 07, 2008 3:51 AM
Hi,

I tried using:

Color c1 = Color.FromArgb(5,5,5)
Color c2 = Color.FromArgb(5,5,5)

And I remember it returned false. It could be my error, because I tried it very quickly.




Thanks,
Aw
Joan Venge  Friday, March 07, 2008 4:21 AM

You can use google to search for other answers

Custom Search

More Threads

• User Settings Initial Setup?
• Invoking NodeMouseClick event
• Problem in scrollable gridView when the binding data is smaller
• Parent/Child Winforms Datagrid Filtering
• C# Windows Form Application
• Draw Graph using Math()
• form's UserControl.AutoSize property keeps resetting itself to true.
• Sharing
• Enter key on message box confused with enter key in form
• Reduce the height of textbox control