Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

moving control problem in runtime.

Posted on 2004-08-10
5
Medium Priority
?
335 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…
Suggested Courses

618 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