Solved

How Can I fix my MouseHover Event?

Posted on 2016-11-03
14
27 Views
Last Modified: 2016-11-03
I have an application that I have been adding bells and whistles too for the last few months.  I'm currently using VS2015 with the Visual Basic.net language. I have also been using stored procedures instead of adding the SQL queries in the vb code. It has a few benefits including a cleaner vb code.  We manufacture widgets, these widgets require component and assembly drawings. During the process of manufacturing, we are always trying to improve our processes and products. Part of this process is to us ECO (Engineering Change Order). The ECO has 5 status levels. These are Submitted, Pending, Changed, Rejected & On Hold. The Application I'm working on is a drawing viewer which has the ability to enter ECOs at any location in the facility.  One of the features of this viewer is the ECO Status of a print when you open it. This flags the person viewing the print where the print is in the ECO process. We have chosen to use Visual in form of Image and Text to show the status. The image is shown by this code:

 Private Sub GetCurECOStatus()
        Using conn As New SqlConnection(connectionString)
            Using (conn)
                Dim cmd As New SqlCommand()
                cmd.Connection = conn
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "sp_frmCPS_GetCurECOStatus"
                cmd.Parameters.AddWithValue("Partnum", txtPartNum.Text)
                If conn.State = ConnectionState.Closed Then
                    conn.Open()
                End If
                Dim r As SqlDataReader = cmd.ExecuteReader()
                If r.HasRows Then
                    r.Read()
                    Dim rs = r.GetString(1)
                    If rs = "Submitted" Then
                        Dim thePic As Object = My.Resources.red_sad2
                        pbECOStatus.BackgroundImage = thePic
                    ElseIf rs = "Pending" Then
                        Dim thePic As Object = My.Resources.yellow_calm
                        pbECOStatus.BackgroundImage = thePic
                    ElseIf rs = "Changed" Then
                        Dim thePic As Object = My.Resources.green_happiness
                        pbECOStatus.BackgroundImage = thePic
                    ElseIf rs = "Rejected" Then
                        Dim thePic As Object = My.Resources.purple_surprised
                        pbECOStatus.BackgroundImage = thePic
                    ElseIf rs = "On Hold" Then
                        Dim thePic As Object = My.Resources.blue_muted
                        pbECOStatus.BackgroundImage = thePic
                    End If
                    r.Close()
                End If
            End Using
        End Using

Open in new window



And the text is shown using a MouseHover Event of a PictureBox Control using this code:

 
  Private Sub pbECOStatus_MouseHover(sender As Object, e As EventArgs) Handles pbECOStatus.MouseHover
        Dim tt As New ToolTip()
        Dim pSubmitted As Image = My.Resources.red_sad2
        Dim pPending As Image = My.Resources.yellow_calm
        Dim pChanged As Image = My.Resources.green_happiness
        Dim pRejected As Image = My.Resources.purple_surprised
        Dim pOnHold As Image = My.Resources.blue_muted

        If pbECOStatus.Image Is pSubmitted Then
            tt.SetToolTip(pbECOStatus, "Submitted")
        ElseIf pbECOStatus.Image Is pPending Then
            tt.SetToolTip(pbECOStatus, "Pending")
        ElseIf pbECOStatus.Image Is pChanged Then
            tt.SetToolTip(pbECOStatus, "Changed")
        ElseIf pbECOStatus.Image Is pRejected Then
            tt.SetToolTip(pbECOStatus, "Rejected")
        ElseIf pbECOStatus.Image Is pOnHold Then
            tt.SetToolTip(pbECOStatus, "On Hold")
        End If
    End Sub

Open in new window


The image portion of the code works great, the MouseHover Event does not work.

I have been scratching my head for a couple days on this and have not been able to figure out why the hover messages are not working. I use this same SetToolTip on other MouseHover Events and they work without issue.  I do have all the images in the Resources folder and they all show up in the suggestion list when I'm coding.

Any help would be greatly appreciated.
0
Comment
Question by:Steve Williams
  • 7
  • 5
14 Comments
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41872152
I'll make up a VB project to test with when I have a moment but what happens if you change the last ElseIf to just an Else?  Does everything show up as "On Hold" tool tip?
0
 
LVL 1

Author Comment

by:Steve Williams
ID: 41872293
@Dustin, That doesn't work. it won't let me compile. get red squigglies under "Is pOnHold"

@Jim:
 I wasn't sure if SQL was relevant or not for this topic due to the SQL coding in the image portion. Thanks!
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41872302
I mean, change it to an Else statement not just change the word:
 Private Sub pbECOStatus_MouseHover(sender As Object, e As EventArgs) Handles pbECOStatus.MouseHover
        Dim tt As New ToolTip()
        Dim pSubmitted As Image = My.Resources.red_sad2
        Dim pPending As Image = My.Resources.yellow_calm
        Dim pChanged As Image = My.Resources.green_happiness
        Dim pRejected As Image = My.Resources.purple_surprised
        Dim pOnHold As Image = My.Resources.blue_muted

        If pbECOStatus.Image Is pSubmitted Then
            tt.SetToolTip(pbECOStatus, "Submitted")
        ElseIf pbECOStatus.Image Is pPending Then
            tt.SetToolTip(pbECOStatus, "Pending")
        ElseIf pbECOStatus.Image Is pChanged Then
            tt.SetToolTip(pbECOStatus, "Changed")
        ElseIf pbECOStatus.Image Is pRejected Then
            tt.SetToolTip(pbECOStatus, "Rejected")
        Else
            tt.SetToolTip(pbECOStatus, "On Hold")
        End If
    End Sub

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41872313
No prob..
0
 
LVL 1

Author Comment

by:Steve Williams
ID: 41872321
@Dustin, that is getting closer now it just shows "On Hold" during the hover regardless of status.
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41872324
So the problem is the way that you are comparing to see which tooltip to use.  Does it work if you use an equals sign vs the "is" operator?
0
IT, Stop Being Called Into Every Meeting

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!

 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41872329
Hmm I just noticed, it looks like in your first code block you are setting .BackgroundImage but in your second code you are looking at .Image
0
 
LVL 1

Author Comment

by:Steve Williams
ID: 41872340
@Dustin

"=" Operator is not defined for types 'Image'

Also, I had the code set to BackgroundImage and it makes no difference.
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41872360
It should make a difference, because they are different properties--  if you try:
  Private Sub pbECOStatus_MouseHover(sender As Object, e As EventArgs) Handles pbECOStatus.MouseHover
        Dim tt As New ToolTip()
        Dim pSubmitted As Image = My.Resources.red_sad2
        Dim pPending As Image = My.Resources.yellow_calm
        Dim pChanged As Image = My.Resources.green_happiness
        Dim pRejected As Image = My.Resources.purple_surprised
        Dim pOnHold As Image = My.Resources.blue_muted

        If pbECOStatus.BackgroundImage Is pSubmitted Then
            tt.SetToolTip(pbECOStatus, "Submitted")
        ElseIf pbECOStatus.BackgroundImage Is pPending Then
            tt.SetToolTip(pbECOStatus, "Pending")
        ElseIf pbECOStatus.BackgroundImage Is pChanged Then
            tt.SetToolTip(pbECOStatus, "Changed")
        ElseIf pbECOStatus.BackgroundImage Is pRejected Then
            tt.SetToolTip(pbECOStatus, "Rejected")
        ElseIf pbECOStatus.BackgroundImage Is pOnHold Then
            tt.SetToolTip(pbECOStatus, "On Hold")
        End If
    End Sub

Open in new window


It doesn't work?
0
 
LVL 12

Accepted Solution

by:
Dustin Saunders earned 500 total points
ID: 41872366
Here's a sample.  Non-functional:
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim img1 As Image = Image.FromFile("C:\\test\\smile.jpg")

        PictureBox1.BackgroundImage = img1

        Dim tt As New ToolTip()
        If PictureBox1.Image Is img1 Then
            tt.SetToolTip(PictureBox1, "Is the image")
        Else
            tt.SetToolTip(PictureBox1, "Is not the image")
        End If

    End Sub
End Class

Open in new window

vbImage1.png
Now, I look at BackgroundImage instead:
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim img1 As Image = Image.FromFile("C:\\test\\smile.jpg")

        PictureBox1.BackgroundImage = img1

        Dim tt As New ToolTip()
        If PictureBox1.BackgroundImage Is img1 Then
            tt.SetToolTip(PictureBox1, "Is the image")
        Else
            tt.SetToolTip(PictureBox1, "Is not the image")
        End If

    End Sub
End Class

Open in new window

vbImage2.png
0
 
LVL 1

Assisted Solution

by:Steve Williams
Steve Williams earned 0 total points
ID: 41872515
@ Dustin

The My.Resources creates a new instance of an image every time it is called, as I was just told by a fellow coder, so this will not work for what I'm trying to do.  So my fix was to make the new variables of each image in my Global variable class which is called "GVar" here are the new variables as functioning.

Public Class GVar  
    Public Shared pSubmitted As Image = Image.FromFile("C:\IMAGES\red-sad2.png")
    Public Shared pPending As Image = Image.FromFile("C:\IMAGES\yellow-calm.png")
    Public Shared pChanged As Image = Image.FromFile("C:IMAGES\green-happiness.png")
    Public Shared pRejected As Image = Image.FromFile("C:\IMAGES\purple-surprised.png")
    Public Shared pOnHold As Image = Image.FromFile("C:\IMAGES\blue-muted.png")

Open in new window


Here is what I changed the Image portion to, to work with the new variables.

 Private Sub GetCurECOStatus()
        Using conn As New SqlConnection(connectionString)
            Using (conn)
                Dim cmd As New SqlCommand()
                cmd.Connection = conn
                cmd.CommandType = CommandType.StoredProcedure
                cmd.CommandText = "sp_frmCPS_GetCurECOStatus"
                cmd.Parameters.AddWithValue("Partnum", txtPartNum.Text)
                If conn.State = ConnectionState.Closed Then
                    conn.Open()
                End If
                Dim r As SqlDataReader = cmd.ExecuteReader()
                If r.HasRows Then
                    r.Read()
                    Dim rs = r.GetString(1)
                    If rs = "Submitted" Then
                        pbECOStatus.BackgroundImage = GVar.pSubmitted
                    ElseIf rs = "Pending" Then
                        pbECOStatus.BackgroundImage = GVar.pPending
                    ElseIf rs = "Changed" Then
                        pbECOStatus.BackgroundImage = GVar.pChanged
                    ElseIf rs = "Rejected" Then
                        pbECOStatus.BackgroundImage = GVar.pRejected
                    ElseIf rs = "On Hold" Then
                        pbECOStatus.BackgroundImage = GVar.pOnHold
                    End If
                    r.Close()
                End If
            End Using
        End Using
    End Sub

Open in new window


and last but not least here is the text portion using the MouseHover event...

    Private Sub pbECOStatus_MouseHover(sender As Object, e As EventArgs) Handles pbECOStatus.MouseHover
        If pbECOStatus.BackgroundImage Is GVar.pSubmitted Then
            tt.SetToolTip(pbECOStatus, "Submitted")
        ElseIf pbECOStatus.BackgroundImage Is GVar.pPending Then
            tt.SetToolTip(pbECOStatus, "Pending")
        ElseIf pbECOStatus.BackgroundImage Is GVar.pChanged Then
            tt.SetToolTip(pbECOStatus, "Changed")
        ElseIf pbECOStatus.BackgroundImage Is GVar.pRejected Then
            tt.SetToolTip(pbECOStatus, "Rejected")
        ElseIf pbECOStatus.BackgroundImage Is GVar.pOnHold Then
            tt.SetToolTip(pbECOStatus, "On Hold")
        End If
    End Sub

Open in new window


Here is the Status "Changed" FunctioningHere is the Status "Submitted" Functioning
0
 
LVL 1

Author Closing Comment

by:Steve Williams
ID: 41872516
Dustin, I'm awarding you all the points because you helped get the correct answer Thank you!
0
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41872528
Glad to see you got it going-- for the record I like the graphics on your UI!
1

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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

19 Experts available now in Live!

Get 1:1 Help Now