?
Solved

moving control problem in runtime.

Posted on 2004-08-10
5
Medium Priority
?
329 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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 86

Accepted Solution

by:
Mike Tomlinson earned 300 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

771 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