Solved

How can I check picturebox backcolor ?

Posted on 2007-11-27
5
240 Views
Last Modified: 2008-02-01
For example if picturebox1 backcolor is black then ....
0
Comment
Question by:waddhah
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

726 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