Results 1 to 5 of 5

Thread: [RESOLVED] VB6 - Mouse move on Shape1

  1. #1
    Lively Member
    Join Date
    Mar 12
    Posts
    127

    Resolved [RESOLVED] VB6 - Mouse move on Shape1

    I want to execute an instruction each time the mouse moves over a shape (a rectangle).
    Picture1 control, for example, has that property. But when I try to find the same option in shape it doesn't exists.

    How can I solve this situation?

    I've thought about creating a matrix of coordenates (x,y) and if the mouse position is at some point of those coordinates then, execute the instruction. In any case, explain me how can I accomplish that.

  2. #2
    Hyperactive Member gibra's Avatar
    Join Date
    Oct 09
    Location
    ITALY
    Posts
    394

    Re: VB6 - Mouse move on Shape1

    Need to check coordinates on Form_Move event (or relative container of the shape).
    Code:

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        If X >= Shape1.Left And X <= (Shape1.Left + Shape1.Width) And Y >= Shape1.Top And Y <= (Shape1.Top + Shape1.Height) Then
            Label1.Caption = "IN"
        Else
            Label1.Caption = "OUT"
        End If
    End Sub

  3. #3
    Frenzied Member
    Join Date
    Sep 06
    Posts
    1,259

    Re: VB6 - Mouse move on Shape1

    Quote Originally Posted by Jose_VB View Post
    I've thought about creating a matrix of coordenates (x,y) and if the mouse position is at some point of those coordinates then, execute the instruction. In any case, explain me how can I accomplish that.
    Try this
    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Const x1 As Single = 1000
        Const x2 As Single = 4000
        Const y1 As Single = 1000
        Const y2 As Single = 4000
        
        If X > x1 And X < x2 And Y > y1 And Y < y2 Then
            Me.Caption = "moving inside region"
        Else
            Me.Caption = "moving outside region"
        End If
    End Sub

  4. #4
    Frenzied Member
    Join Date
    Aug 11
    Location
    B.C., Canada
    Posts
    1,838

    Re: VB6 - Mouse move on Shape1

    from 4x2y's example

    Code:
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim x1 As Single, x2 As Single
        Dim y1 As Single, y2 As Single
        
        x1 = Shape1.Left
        x2 = Shape1.Left + Shape1.Width
        y1 = Shape1.Top
        y2 = Shape1.Top + Shape1.Height
        
        If X > x1 And X < x2 And Y > y1 And Y < y2 Then
            Me.Caption = "moving inside region"
        Else
            Me.Caption = "moving outside region"
        End If
    End Sub

  5. #5
    Lively Member
    Join Date
    Mar 12
    Posts
    127

    Re: VB6 - Mouse move on Shape1

    Thank you very much to all.
    It works perfectly.

Posting Permissions

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