Solved

How can I check picturebox backcolor ?

Posted on 2007-11-27
5
245 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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