CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Mousemove

  1. #1
    Join Date
    Feb 2001
    Posts
    17

    Mousemove

    I'm trying to make my own commadButton. I want the button border stays invissible untile the mouse moveover it, and the border disappear when mouse move away. I'm using a pictureBox and four lines around it to make my own button. Under the mousemove event of the pictureBox, I write code to change the line color so the line will appear and it looks like a button. The problem is when I move the mouse away from the pictureBox. the line still there. What should I do to make the line disappear and make the button stays inviable when I move the mouse away.


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Mousemove

    Use the SetCapture and ReleaseCapture API. Here is a working example. Start a new project. Add a command button to the form. Paste this code into the general declarations section of the form. Run it and move the mouse over the button then away from it. PS. This is not my code. I found it on the Web somewhere. Since you are creating your own control, you may have to finagle with it a bit.

    option Explicit

    private Declare Function SetCapture Lib "user32" (byval hwnd as Long) as Long
    private Declare Function ReleaseCapture Lib "user32" () as Long


    'Code:
    'Put this code in MouseMove event. In this example, I put a
    'CommandButton on a
    'form with the name Command1

    private Sub Command1_MouseMove(Button as Integer, Shift as Integer, X _
    as Single, Y as Single)
    static CtrMov as Boolean
    static Counter as Long
    Counter = Counter + 1
    With Command1 'Change this 'Command1' to your control name
    If (X < 0) Or (Y < 0) Or (X > .Width) Or (Y > .Height) then
    ReleaseCapture
    CtrMov = false
    Command1.BackColor = &HFF&
    Command1.Caption = " Not Over " & Counter
    Command1.Refresh
    'Put here your code to LostMouseFocus
    'for example:
    me.print "LostMouseFocus"

    else
    SetCapture .hwnd
    If CtrMov = false then ' do this only once per "over"
    CtrMov = true
    Command1.BackColor = &HFFFFFF
    Command1.Caption = " Over " & Counter
    Command1.Refresh
    'Put here your code to GetMouseFocus
    'for example:
    me.print "GetMouseFocus"

    End If
    End If
    End With
    End Sub






    John G

  3. #3
    Join Date
    May 2005
    Posts
    1

    Re: Mousemove

    Fine your sample Jonh, but you must to specify the conditionals again.

  4. #4
    Join Date
    Apr 2005
    Posts
    14

    Re: Mousemove

    You can also change the lines but putting a mousemove event on the form itself or other nearby objects. In these events you can change the lines back to the color you want. This is easier if you are more new to vb.

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

Featured