Solved

How can I check picturebox backcolor ?

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

757 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

20 Experts available now in Live!

Get 1:1 Help Now