Solved

moving control problem in runtime.

Posted on 2004-08-10
5
312 Views
Last Modified: 2010-05-02
helloo experts
here is the problem
I am trying to move label from location to another on a form in runtime by using mousedown and mousemove events but the problem is when the mouse goes over a control on the form while moving the label I lost the actual form.mouse(x,y),,,, in another meaning it becomes the x,y of that control.
I have alote of controls on the form so it is hard to write mousemove event for each one.
my Question is how to keep this label stick to mouse whatever the control under mouse or how to get the actual form x,y.
regards
0
Comment
Question by:fadloun
5 Comments
 
LVL 3

Expert Comment

by:TILL
ID: 11770184
You have to create an api hook and on WM_MOUSEMOVE message use GetCursorPos to extract the position of the cursor relative to the screen.
0
 
LVL 23

Assisted Solution

by:Ioannis Paraskevopoulos
Ioannis Paraskevopoulos earned 50 total points
ID: 11771334
I wrote this code and works fine:


Dim MouseD As Boolean
Dim curX As Integer
Dim curY As Integer

Private Sub label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
   MouseD = True
   curX = Label1.Left
   curY = Label1.Top
End Sub

Private Sub label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
   If MouseD = True Then
      X = curX + X
      Y = curY + Y
      Label1.Move X, Y
      Label2.Caption = X
      Label3.Caption = Y
      curX = X
      curY = Y
      Label1.Refresh
   End If
End Sub

Private Sub label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
   MouseD = False
End Sub
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 75 total points
ID: 11772544
Option Explicit

Private mouseDown As Boolean
Private startX As Single, startY As Single

Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton Then
        startX = X
        startY = Y
        mouseDown = True
    End If
End Sub

Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton And mouseDown Then
        Label1.Move Label1.Left + X - startX, Label1.Top + Y - startY
    End If
End Sub

Private Sub Label1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbLeftButton And mouseDown Then
        mouseDown = False
    End If
End Sub
0
 
LVL 5

Author Comment

by:fadloun
ID: 11773242
Idle mind
Good Good Good ,,,,
have a good day ,,,,thanx

0
 
LVL 5

Author Comment

by:fadloun
ID: 11773284
sorry jyparask
I did not read your solution
it is also working
gonna split points
thanx allll
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question