11-24-2001, 10:42 PM
I would like to make a program that has a sort of selection idea to it. So basically, u click and hold and drag to where u want to stop selecting (like the windows desktop). How would I find the mouse position on the form?
11-24-2001, 11:23 PM
<pre><font color=blue>Private Sub</font color=blue> Form_MouseMove(Button <font color=blue>As Integer</font color=blue>, Shift <font color=blue>As Integer</font color=blue>, X <font color=blue>As Single</font color=blue>, Y <font color=blue>As Single</font color=blue>)
Label1.Caption = X & " by " & Y
<font color=blue>End Sub</font color=blue></pre>
11-25-2001, 09:23 AM
In your case, doing what robot suggested is probably sufficient, but here's a tip:
If you ever need to get the position of the cursor on the form no matter where it is (i.e. on top of a control, etc), you can use this code:
Put this in the <font color=green>General Declarations</font color=green>.
<font color=blue>Private Declare</font color=blue> <font color=blue>Function</font color=blue> GetCursorPos <font color=blue>Lib</font color=blue> "user32" (lpPoint <font color=blue>As</font color=blue> POINTAPI) <font color=blue>As Long</font color=blue>
<font color=blue>Private Type</font color=blue> POINTAPI
X <font color=blue>As Long</font color=blue>
Y <font color=blue>As Long</font color=blue>
<font color=blue>End Type</font color=blue>
-----------</pre>Put this whereever you want to check for the position (timer, mousemove, etc).
<font color=blue>Dim</font color=blue> oCoords <font color=blue>As</font color=blue> POINTAPI
Me.Cls <font color=green> 'You replace these two lines with whatever you want to do with the coords.</font color=green>
Me.Print oCoords.X & ", " & oCoords.Y <font color=green>'Use oCoords.X and .Y to get the X and Y position.</font color=green>
11-25-2001, 10:00 AM
Bear in mind that GetCursorPos returns the screen co-ordinates of the cursor and it uses Pixels not Twips.
11-25-2001, 10:04 AM
Oh well, it's still probably good for something. I was thinking GetCursorPos was for the form, and you used ClientToScreen to change it to screen coords.
11-25-2001, 02:55 PM
Alright, all very helpful. Thanx.
11-29-2001, 07:04 AM
'just enter this into a form and run it
'The cls seems to slow my comp down bad..maybe i got no memory left or whatever, it all should work.
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
Dim MousePoint As POINTAPI
Dim DragPointX, DragPointY
Private Sub Form_Load()
Me.ScaleMode = 3
Me.WindowState = 2
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MousePressed = MousePressed + 1
ScreenToClient Form1.hwnd, MousePoint
If MousePressed = 1 Then
DragPointX = MousePoint.X
DragPointY = MousePoint.Y
'Cls 'Causing me problems..slowing comp down bad..maybe i should restart...
Line (DragPointX, DragPointY)-(MousePoint.X, MousePoint.Y), vbGreen, B
Loop Until MousePressed = 0
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
MousePressed = 0
12-04-2001, 05:17 AM
Just a general tip:
Twips suck, use pixels always
12-04-2001, 09:43 AM
Unfortunately, VB uses twips for forms and controls external co-ordinate systems so you can not avoid it completely.
12-04-2001, 11:21 AM
Banjo, I've been able to switch the form to use pixels. Just set the scalemode to pixels and you're set.
On the other hand, what do you mean when you say "controls external coordinate systems?" Do you mean that there are external controls that force you to use twips?
12-04-2001, 11:55 AM
With a form, the Top, Left, Height and Width properties are all in twips. You can not specify them in anything else. This also applies to postioning controls on a form as well. Their postion properties do not use the Form's scalemode.
12-05-2001, 05:17 AM
You're right about a forms .left, .top, .width and .height properties always being in twips, however these are different from their .scalewidth counterparts even when scaled, to reflect the fact that forms have titlebars and margins.
If the forms scalemode in pixels, then the dimensions/positions of child controls on that form will be in pixels.