Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag and drop objects

Status
Not open for further replies.

rpg121

Programmer
Mar 14, 2001
89
US
How do you allow the user to drag an object (picture, text or anything else) and drop it somewhere else on the form and how do you execute a sub when that object is dropped

RPG121
 
O.k. this is based on a form with one textbox named text1 on it. I did it in access but it should work in vb also.
Code:
Option Compare Database
Option Explicit
Dim ObjectNamed As String

Private Sub Detail_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
on error goto Err
    If ObjectNamed = "Text1" And Button = 2 Then
        Text1.Left = X
        Text1.Top = Y
    End If
    ObjectNamed = ""
Err:
End Sub

Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Shift = 1 Then
        ObjectNamed = "Text1"
    End If
End Sub
If you hold shift and right click on the text box then right click elsewhere on the form it moves the textbox. You can shorten this up if you know how to set the textbox as a variable. I have never had to do it before so I am not sure how to (maybe you could tell me). Also in access this still brings up the right click menu, however you should not have that problem if you are creating your own program. Dragging should not be much more difficult. The hardest questions always have the easiest answers.
 
This solution isn't excactly what i needed but that's okay, i'll just wait for another post. I need it for a card game or special training game. You said you use Access's VBA. Excel can't be harder. If you can figure this out post a response. I need to access a ltd file without activating (that's how I do it now and it goes too slow and I tried the screenupdating command and it doesn't work with word pad.) I think it's the open and close commands but you should tell me all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top