Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Intermediate
Feb 12, 2001

Confining Your Mouse to a Form


With Modal forms there is a need to restrict the movement of the mouse to the form until user closes the form. This can be achieved by using the ClipCursor API. ClipCursor API takes one parameter, the rectangular area of type RECT to which the mouse will be confined.
 
Public Sub Clip()1
Dim iRect as RECT
' first populate the iRect with Form's dimensions & then call the ClipCursor API
With iRect
  .Left = Form1.Left
  .Top = Form1.Top
  .Right = Form1.Left + Form1.Width
  .Bottom = Form1.Top + Form1.Height
End With
ClipCursor iRect
End Sub
' and finally in Form's Unload event call ClipCursor again to release the mouse :-
ClipCursor 0&

Note that RECT expects dimensions of the form in pixels, as is the case with all APIs. Set the form's ScaleMode to vbPixels before calling the ClipCursor API.
Sachin Nigam
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap