Results 1 to 25 of 25

Thread: Is that possible to add ToolTipText for different part of the picture?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Is that possible to add ToolTipText for different part of the picture?

    Hi, as i know, the VB can add the tooltiptext in the picture. But what i want is i want to assign few of the tooltiptext in different part of my picture, is it possible? For example, i have a map and there are several buildings that i want to assign the tooltiptext, as the mouse move over or click at that building, the tooltiptext show up. How it can be done? Any advise?
    I'm still on the path of learning....

  2. #2
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    You could use the mouse move or mouse click events to get the location on the image and change the tool tip depending on the x and y values.

  3. #3
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Is that possible to add ToolTipText for different part of the picture?

    Quote Originally Posted by longwolf
    You could use the mouse move or mouse click events to get the location on the image and change the tool tip depending on the x and y values.
    Here's an example where I've only specified the X coordinates, but It demonstrates the basic concept. Put a PicBox about 2" High x 3" Wide and two Labels on your form.

    Code:
    Option Explicit
    
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Label1.Caption = "X = " & X
       Label2.Caption = "Y = " & Y
       If X > 300 And X <= 700 Then
          Picture1.ToolTipText = "300 to 700"
       End If
       If X > 800 And X < 1200 Then
          Picture1.ToolTipText = "800 to 1200"
       End If
       If X > 1300 And X < 1700 Then
          Picture1.ToolTipText = "1300 to 1700"
       End If
       If X > 1800 And X < 2200 Then
          Picture1.ToolTipText = "1800 to 2200"
       End If
    End Sub
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Is that possible to add ToolTipText for different part of the picture?

    The code works, CDDRIVE. But not in my program. My map support zoom in and zoom out. When i try to apply your code in my program, the tooltiptext show in everywhere of my map and it seems like it didn't follow the condition (X > 300 And X <= 700). How can i solve it?
    I'm still on the path of learning....

  5. #5
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    You'll need to divide the x and y values by the percentage of zoom added to the image.
    Store zoom % in a module level variable when the size is changed.

  6. #6
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Is that possible to add ToolTipText for different part of the picture?

    Quote Originally Posted by longwolf
    You'll need to divide the x and y values by the percentage of zoom added to the image.
    Store zoom % in a module level variable when the size is changed.
    I must say that I'm a bit confused. Am I to understand that the PicBox dimensions remain constant but the size of the image increases when it's zoomed in and decreases when zoomed out? If that's the case how would that effect that code? On the other hand, are you saying that the PicBox dimensions change (AutoSize=True) when zooming in and out?

    I've been playing with the PicBox while I've been typing this. I've maximized the form and made the PicBox the same width as the form. Nothing that I do changes the trigger points of the X positions in that code and I wouldn't expect it too, since X is referenced from the left edge of the box and Y is referenced from the top edge.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Is that possible to add ToolTipText for different part of the picture?

    Hi, longwolf. Can you show me some sample code for my better understanding? Thanks a lot.
    I'm still on the path of learning....

  8. #8
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    Thinking about it, I didn't say enough.
    Assuming that he also has scroll bars, he will also need to add the scroll values to the X and Y before dividing by the zoom percentage.
    I wrote something like this that converted the x/y to longitude and latitude.

    Does it make sense now?

  9. #9
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    Quote Originally Posted by cheowkwen
    Hi, longwolf. Can you show me some sample code for my better understanding? Thanks a lot.
    Are you using scroll bars? Are their max values set to the full size of the zoomed pic?

    If you can show your code that handles the zooming, i'll try to tweak it.

  10. #10
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    Thinking more about it, you may or may not need add the scrolls to the x and y.
    It depends on how you're handling the scrolling.

    If you're using one picture box inside another, you won't need it.
    The mouse pos will be correct.
    But if you're copying the visible/scrolled-to section of the image, then you need the x/y offsets.

    Lets say your image is 600x600 pixels and so is your picturebox.
    When your pic is at actual size, the zoom would = 1
    So x/1 gives the actual pixel.

    But if you double the pic size to 1200, your zoom % = 2
    So x/2 gives the pixel value at it's original size.
    Last edited by longwolf; Dec 24th, 2008 at 02:33 AM.

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Is that possible to add ToolTipText for different part of the picture?

    Longwolf, is that necessary to divide the x and y by the zoom%? I have two labels in the form which showing the corresponding coordinates(latitude and longitude) of the map whenever the mouse move over the map. Based on the CDDRIVE's code, it seem that as long as the condition are obeys, then the tooltips should show up since what shown up in the two labels will be used to check whether the condition is fulfilled or not . Is this make sense?
    I'm still on the path of learning....

  12. #12
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    If you aren't zooming the pic, you won't need to convert the x and y.

    Back to my earlier example, Say the map image is 600x600 and the far left edge is over the Bering Strait.
    so you move the mouse to pixel 600, you could change the tool tip to "Bering Strait'.

    But if you double the size of the image, then move the mouse to pixel 600, you'd still get the tool tip "Bering Strait'.
    But you will be over Spain.

    To help you any more, I'd need to know which method of zooming you're using.

  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Is that possible to add ToolTipText for different part of the picture?

    Ok. below is my zooming code part. The code is too complex, therefore i only show the zooming part.

    Code:
    With zoom
            'find map coords
                oldWidth = .Right - .Left
                oldHeight = .Bottom - .Top
                
                If oldWidth < 20 Then Exit Sub
                
                ratioX = oldWidth / Map.ScaleWidth
                ratioY = oldHeight / Map.ScaleHeight
                
                zoomX = X * ratioX + .Left
                zoomY = Y * ratioY + .Top
            'find new center
            
                .Left = zoomX - oldWidth / 2
                .Right = .Left + oldWidth
                .Top = zoomY - oldHeight / 2
                .Bottom = .Top + oldHeight
            'zoom in by 2
                .Left = .Left + oldWidth / 4
                .Right = .Right - oldWidth / 4
                .Top = .Top + oldHeight / 4
                .Bottom = .Bottom - oldHeight / 4
                
                BorderCheck
                
                Map.Cls
                Map.PaintPicture mappic, 0, 0, Map.ScaleWidth, Map.ScaleHeight, _
                  .Left, .Top, .Right - .Left, .Bottom - .Top
            End With
    Code:
     If PushFlag Then
            'push routine
            With zoom
            'find map coords
                oldWidth = .Right - .Left
                oldHeight = .Bottom - .Top
                
                ratioX = oldWidth / Map.ScaleWidth
                ratioY = oldHeight / Map.ScaleHeight
                
    
                pushX = StartX * ratioX + .Left
                pushY = StartY * ratioY + .Top
                
                zoomX = X * ratioX + .Left
                zoomY = Y * ratioY + .Top
    
            'find new center
    
                .Left = .Left + pushX - zoomX
                .Right = .Left + oldWidth
                .Top = .Top + pushY - zoomY
                .Bottom = .Top + oldHeight
                
                StartX = X
                StartY = Y
                
                BorderCheck
                
                Map.Cls
                Map.PaintPicture mappic, 0, 0, Map.ScaleWidth, Map.ScaleHeight, _
                  .Left, .Top, .Right - .Left, .Bottom - .Top
            End With

    Code:
    If PushFlag Then
            PushFlag = False
            
        ElseIf SelectFlag Then
            'select routine
            
            SelectFlag = False
            Map.Refresh
            Map.AutoRedraw = True
    
            With zoom
            'find map coords
                oldWidth = .Right - .Left
                oldHeight = .Bottom - .Top
                
                ratioX = oldWidth / Map.ScaleWidth
                ratioY = oldHeight / Map.ScaleHeight
                
    
                pushX = StartX * ratioX + .Left
                pushY = StartY * ratioY + .Top
                
                zoomX = X * ratioX + .Left
                zoomY = Y * ratioY + .Top
                
                If pushX > zoomX Then
                    holdX = pushX
                    pushX = zoomX
                    zoomX = holdX
                End If
                
                If pushY > zoomY Then
                    holdX = pushY
                    pushY = zoomY
                    zoomY = holdX
                End If
    I'm still on the path of learning....

  14. #14
    Frenzied Member
    Join Date
    Jun 2006
    Posts
    1,098

    Re: Is that possible to add ToolTipText for different part of the picture?

    Quote Originally Posted by cheowkwen
    I have two labels ... showing the ... latitude and longitude ... whenever the mouse move over the map
    In that case, you've already done most of the work. Just use the lat/long values that you already have to determine what the ToolTipText should be.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Is that possible to add ToolTipText for different part of the picture?

    But i have try what CDDRIVE taught and it does not work. It can show the ToolTipText but not according to the condition. It will show at everywhere on the map.
    I'm still on the path of learning....

  16. #16
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    Ok, it looks like you are taking a section of your original map and pasting a resized section of it into another picture box for viewing.

    These variables need to be Module level variables
    Code:
    Private ratioX as Single
    Private ratioY as Single
    
    'And you need to add these also
    Private ShiftX as Single 'holds your zoom.left value
    Private ShiftY as Single 'holds your zoom.top value
    those values will be set in the subs you've shown
    You'll use them in the mouse move event.
    Code:
    Private Sub Map_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Dim trueX as long
       Dim trueY as long
    
       trueX = (X + ShiftX) / ratioX 
       trueY = (Y + ShiftY) / ratioY 
    
       Label1.Caption = "trueX = " & trueX
       Label2.Caption = "trueY = " & trueY
       If trueX > 300 And trueX <= 700 Then
          Map.ToolTipText = "300 to 700"
       End If
       If trueX > 800 And trueX < 1200 Then
          Map.ToolTipText = "800 to 1200"
       End If
       If trueX > 1300 And trueX < 1700 Then
          Map.ToolTipText = "1300 to 1700"
       End If
       If trueX > 1800 And trueX < 2200 Then
          Map.ToolTipText = "1800 to 2200"
       End If
    End Sub

  17. #17
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    i may have gotten the math wrong, if the last code doesn't work try it this way
    Code:
       trueX = (X / ratioX) + ShiftX
       trueY = (Y / ratioY) + ShiftY

  18. #18
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    Logophobic should be right.

    If your code is showing the correct longitude and latitude, even when zoomed, then you must have code in your current mouse move event that corrects the x and y.

  19. #19
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Is that possible to add ToolTipText for different part of the picture?

    I've sat on the sidelines since my last post because nothing in any of the subsequent posts changed my opinion. Personally, I think you guys are chasing a red herring. First off, the code I posted was intended as an example to be built upon. It wasn't intended as a complete copy & paste. Besides not having any 'Y' code it also has no provisions for dealing with 'X' values < 300 or > 2200. Therefore any 'X' coordinates less than 300 or greater than 2200 will lock the ToolTip on the screen if exceeded. The ToolTip will read either 300 to 700 or 1800 to 2200. Here's the same code with If branches to deal with 'X' values less than 300 or greater than 2200.

    If you want nothing displayed on those If branches then just use:
    Code:
    If X < 300 Then 
          Picture1.ToolTipText = ""
    ElseIf X > 2200 Then
          Picture1.ToolTipText = ""
    End If
    Same thing but a ToolTip is displayed.
    Code:
    Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
       Label1.Caption = "X = " & X
       Label2.Caption = "Y = " & Y
       If X < 300 Then Picture1.ToolTipText = "Tool tip for X vals < 300"
       If X > 300 And X <= 700 Then
          Picture1.ToolTipText = "300 to 700"
       End If
       If X > 800 And X < 1200 Then
          Picture1.ToolTipText = "800 to 1200"
       End If
       If X > 1300 And X < 1700 Then
          Picture1.ToolTipText = "1300 to 1700"
       End If
       If X > 1800 And X < 2200 Then
          Picture1.ToolTipText = "1800 to 2200"
       ElseIf X > 2200 Then
          Picture1.ToolTipText = "Tool tip for X vals > 2200"
       End If
    End Sub
    Last edited by CDRIVE; Dec 25th, 2008 at 11:24 AM. Reason: Clarity
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  20. #20
    Frenzied Member longwolf's Avatar
    Join Date
    Oct 2002
    Posts
    1,343

    Re: Is that possible to add ToolTipText for different part of the picture?

    CDRIVE, I only considered your code a simple example.
    I have no idea what coords or tips the OP needs, so i didn't try.

    i've been trying to explain the x/y adjustments he needs.

  21. #21
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Is that possible to add ToolTipText for different part of the picture?

    Quote Originally Posted by longwolf
    CDRIVE, I only considered your code a simple example.
    I have no idea what coords or tips the OP needs, so i didn't try.

    i've been trying to explain the x/y adjustments he needs.
    Here's what cheowken posted immediately following my posted code.

    Quote Originally Posted by cheowkwen
    The code works, CDDRIVE. But not in my program. My map support zoom in and zoom out. When i try to apply your code in my program, the tooltiptext show in everywhere of my map and it seems like it didn't follow the condition (X > 300 And X <= 700). How can i solve it?
    What cheowkwen should have posted and what should have been asked is: Which one of the ToolTips was being displayed when this happens? After all, there are 4 ToolTips in the original code.
    Even I didn't ask, because I got caught up in the zooming issue too!

    Merry Christmas, Hanuka, Quanza and Festivious!
    Last edited by CDRIVE; Dec 25th, 2008 at 03:58 PM.
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  22. #22
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Is that possible to add ToolTipText for different part of the picture?

    CDrive

    Seeing as Festivus is a time to voice one's complaints, I have
    a complaint...

    .. you misspelled Festivus (according to Wiki)

    Spoo

  23. #23
    PowerPoster CDRIVE's Avatar
    Join Date
    Jul 2007
    Posts
    2,620

    Re: Is that possible to add ToolTipText for different part of the picture?

    Quote Originally Posted by Spoo
    CDrive

    Seeing as Festivus is a time to voice one's complaints, I have
    a complaint...

    .. you misspelled Festivus (according to Wiki)

    Spoo
    I said "Honey!.... How do you think Festivus is spelled?" "Do you think it's 'vous' or 'vus'?" She said.. " I would spell it 'ous' ." So it her fault. I added an 'i' because I'm tanked! BTW, did Wiki confirm this with Mr Castanzza?
    Last edited by CDRIVE; Dec 25th, 2008 at 04:35 PM. Reason: Too much liquid cheer!
    <--- Did someone help you? Please rate their post. The little green squares make us feel really smart!
    If topic has been resolved, please pull down the Thread Tools & mark it Resolved.


    Is VB consuming your life, and is that a bad thing??

  24. #24
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Is that possible to add ToolTipText for different part of the picture?

    Lol !!

    BTW, now I have another complaint... I've editted this twice .. as "LOL" (all caps),
    and the editor keeps returning it as "Lol". Arrgh.

    And, oh yeah.. Merry Festivus (or Festivious)
    Last edited by Spoo; Dec 25th, 2008 at 05:55 PM.

  25. #25

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Posts
    282

    Re: Is that possible to add ToolTipText for different part of the picture?

    Thank you for all your advise. I am trying now.
    I'm still on the path of learning....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width