|
-
May 23rd, 2009, 12:36 PM
#1
Thread Starter
Member
[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
Last edited by Shadow45o; May 23rd, 2009 at 12:53 PM.
-
May 23rd, 2009, 01:48 PM
#2
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).
-
May 23rd, 2009, 02:14 PM
#3
Thread Starter
Member
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...
-
May 23rd, 2009, 02:34 PM
#4
Re: Check backcolor color of object
 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.
-
May 23rd, 2009, 08:32 PM
#5
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.
-
May 23rd, 2009, 08:51 PM
#6
Thread Starter
Member
Re: Check backcolor color of object
 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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|