Solved

How can I check picturebox backcolor ?

Posted on 2007-11-27
5
234 Views
Last Modified: 2008-02-01
For example if picturebox1 backcolor is black then ....
0
Comment
Question by:waddhah
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20358306
MsgBox Picture1.BackColor
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20358318
If Picture1.BackColor = vbBlack Then Picture1.BackColor = vbRed
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 20358320
Because Color has instance equality, you need to test the component values:

        Dim xColor as Color = Color.Blue

        If PictureBox1.BackColor.A = xColor.A _
            And PictureBox1.BackColor.R = xColor.R _
            And PictureBox1.BackColor.G = xColor.G _
            And PictureBox1.BackColor.B = xColor.B Then
            MsgBox("True")
        End If
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20358355
sorry. I had mistaken it for vb6
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 125 total points
ID: 20358359
This demonstrates why you can't use BackColor = MyColor in a test:
Public Class Form1
 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        PictureBox1.BackColor = Color.Blue

        Dim xColor As Color = Color.FromArgb(255, 0, 0, 255)
 

        If PictureBox1.BackColor.A = xColor.A _

            And PictureBox1.BackColor.R = xColor.R _

            And PictureBox1.BackColor.G = xColor.G _

            And PictureBox1.BackColor.B = xColor.B Then

            MsgBox("True")

        End If
 

        If PictureBox1.BackColor = xColor Then

            MsgBox("True")

        Else

            MsgBox("False")

        End If

    End Sub

End Class

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now