[RESOLVED] Check backcolor color of object
Simple question...is it possible to check the backcolor of an object, like a label for instance?
What I want to do is check if a label's backcolor is green (or some other color) then have something else happen based off the color.
Here is what I tryed, but neither worked...
Code:
if label1.backcolor=color.green then
'stuff goes here
end if
Code:
if label1.backcolor.green then
'stuff goes here
end if
Re: Check backcolor color of object
How do you mean didn't work?
Your second snippet certainly isn't going work, but the first one should work fine.
I've tested it to make sure I'm not going mad. Created a form, added a label and set its back color to black, then tried this code
Code:
If Label1.BackColor = Color.Black Then
MsgBox("yep its black OK")
Else
MsgBox("It isn't black")
End If
To which it dutifully informed me that the label's backcolor was indeed black.
The obvious question is : are you totally sure that the background color of your label is green? (and by that I mean the combination of RGB values that VB recognises as green).
Re: Check backcolor color of object
It shows the error:
"operator '=' is not defined for types 'System.Drawing.Color' and 'System.Drawing.Color'"
So i don't if it is just a stupid mistake or why it isn't working...
Re: Check backcolor color of object
Quote:
Originally Posted by
Shadow45o
It shows the error:
"operator '=' is not defined for types 'System.Drawing.Color' and 'System.Drawing.Color'"
So i don't if it is just a stupid mistake or why it isn't working...
Hmm.. that doesn't make sense. You are not doing anything daft - that should work.
Not sure what to suggest to be honest.
Re: Check backcolor color of object
The '=' operator only exists for a type if it has been defined in that type. '=' is defined for the Color type from .NET 2.0 but it isn't in .NET 1.x. Try using the Equals method instead:
vb.net Code:
If Me.Label1.BackColor.Equals(Color.Green) Then
In future, please provide ALL the information in the first post. The code you used and the error message it produced are always relevant.
Re: Check backcolor color of object
Quote:
Originally Posted by
jmcilhinney
In future, please provide ALL the information in the first post. The code you used and the error message it produced are always relevant.
Ok, and thanks, it works now:wave: