• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

How can I check picturebox backcolor ?

For example if picturebox1 backcolor is black then ....
0
waddhah
Asked:
waddhah
  • 3
  • 2
1 Solution
 
Shanmuga SundaramCommented:
MsgBox Picture1.BackColor
0
 
Shanmuga SundaramCommented:
If Picture1.BackColor = vbBlack Then Picture1.BackColor = vbRed
0
 
PaulHewsCommented:
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
 
Shanmuga SundaramCommented:
sorry. I had mistaken it for vb6
0
 
PaulHewsCommented:
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now