Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CHECK color of shape 2

Status
Not open for further replies.

2009luca

Programmer
Jul 27, 2013
222
IT
i have a series of shape, similar shp(0), shp(1)... shp(N) on label 1.

Possible to check with mouse move on restricted area of label1 the color of shape and the index of single shape shp(n)?

note:
i can have only tree color:

'VERDE &H0000C000&
'ARANCIONE &H000080FF&
'ROSSO &H000000FF&

 
The easiest way of doing this might be to use a picturebox control instead of a shape control
 
Still, if you insist on using shapes, then something like the following:

Code:
[COLOR=blue]Option Explicit

Private Declare Function PtInRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long 'pt As POINTAPI) As Long

Private Type POINTAPI
        x As Long
        y As Long
End Type

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    CLicktest x, y
End Sub

Private Sub CLicktest(x As Single, y As Single)
    Dim ShapeRect As RECT
    Dim myShape As Shape
    Dim myPoint As POINTAPI
    
    For Each myShape In Shape1 [COLOR=green]' Shape1 is our control array of shapes[/color]
        With ShapeRect
            .Bottom = myShape.Top + myShape.Height
            .Right = myShape.Left + myShape.Width
            .Top = myShape.Top
            .Left = myShape.Left
        End With
        myPoint.x = x
        myPoint.y = y
        If PtInRect(ShapeRect, x, y) = 1 Then
            ShapeClicked myShape
            Exit For
        End If
    Next
End Sub


Private Sub ShapeClicked(myShape As Shape)
    Debug.Print "Clicked Shape " & myShape.Index
    Debug.Print "Backcolour is &H" & Hex(myShape.BackColor)
End Sub
[/color]
 
Hi strongm,
i sse te code use down click, possible with mouse move?

Note:
all shape are in array, similar:

shp(0)
shp(1)
ecc...
 
2009luca said:
possible with mouse move?

Here is a crazy idea - TRY IT!

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
You can just drop the same code into the MouseMove event. But it may not be the most efficient way, depending on your actual end requirement ..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top