PDA

Ver la versión completa : drag & drop



sscreamm2005
06-01-2003, 05:38
creo q se le llama drag & drop .....
lo que kiero es acer, cuando arrastras un archivo al notepad.exe (C:\WINDOWS\NOTEPAD.EXE) o si tienes en español tu windows seria (C:\WINDOWS\bloc de notas.EXE).... te abre automaticamente el archivo... como podria acer eso en VB?? con saber el path i el filename del archivo arrastrado a la aplicacion me sobra... ALGUIEN SABE?????????????????

spushan
06-01-2003, 08:42
creo que necesitas una libreria .ocx para eso

sscreamm2005
07-01-2003, 20:47
ajajaj q mostro el xabal.... i llo creo q nececitaria un archivo para arrastrarlo tb no? XD

la procima vez especifica un pko + :D

spushan
09-01-2003, 19:10
tu preguntas como se puede hacer eso en VB y yo te respondo que necesitas un libreria .ocx que como bien se sabe son las que usa VB para añadir nuevas funciones y creo que la drag & drop esta en una .ocx
¿te lo he aclarado bastante?

sscreamm2005
09-01-2003, 23:53
mmmmmmm .... encontre un ejemplo de drag & drop i no ace falta usar ninguna dll ni ocx ya que viene en las prpiedades de vb el caso era saber utilizarlo gracias de todos modos por responder ;) para el ke le sea util drag & drop (es el arrastrar por ejemplo un archivo .txt al archivo compilado i abrir automaticamente el txt en el richtextbox o donde kiera ke sea... igual q digo un txt puede ser una imagen o mil cosas...) aki esta el ejemplo:

añadir un picturebox i un timer(interval = 0)

__________________________________________________ ______
__________________________________________________ ______

en un form... introducir el siguiente code:
__________________________________________________ ______
__________________________________________________ ______

Option Explicit
'* only thing to do is make a form with a picturebox on it, make the picturebox
' invisible, make the form's oledragdrop mode 'manual' and then this should work
' good for draggin' and droppin' images around.

' got through trial and error. This is returned in 'effect' when you drop files
' on the form.
Const vbDropFilesFromExplorer = 7
' got through trial and error. This is returned if you drag from form to form.
Const vbDropPictureFromForm = 3

Dim Moving As Boolean
Dim ActiveIndex As Integer
Dim OldX, NewX As Integer
Dim OldY, NewY As Integer

Private Sub Form_Load()
Moving = False
mMove.Initialize Timer1
Form2.Show
End Sub

'here's the actual drag'n'drop work
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
Dim NewIndex As Integer

' check to see source of drop event.
Select Case Effect
Case vbDropFilesFromExplorer
'data.files is a collection of strings that are absolute paths to any files
'dragged and dropped to the form.
For i = 1 To Data.Files.Count
NewIndex = Picture1.Count + 1

'check to see if we've got an image file
If ImageFileCheck(Data.Files(i)) Then
Load Picture1(NewIndex)
Picture1(NewIndex).Picture = LoadPicture(Data.Files(i))
Picture1(NewIndex).Visible = True
End If
Next i

Case vbDropEffectCopy
If Data.GetFormat(vbCFBitmap) Then
NewIndex = Picture1.Count + 1
Load Picture1(NewIndex)
Picture1(NewIndex).Picture = Data.GetData(vbCFBitmap)
Picture1(NewIndex).Visible = True
Picture1(NewIndex).ZOrder
End If

End Select
End Sub

'checks to see if we've got an image file
Function ImageFileCheck(strFileName As String) As Boolean
Dim strExtention As String

'grab the file's extention
strExtention = Right(strFileName, 3)

'check the extention for an image type
If (strExtention = "bmp") Or (strExtention = "jpg") Or _
(strExtention = "gif") Then
ImageFileCheck = True
Else
ImageFileCheck = False
End If

End Function


Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Picture1(Index).OLEDrag
ElseIf Button = 2 Then
mMove.Begin Me.ActiveControl, X, Y
End If
End Sub

Private Sub Picture1_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then mMove.InProgress X, Y
End Sub

Private Sub Picture1_MouseUp(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then mMove.EndIt
End Sub

Private Sub Picture1_OLEStartDrag(Index As Integer, Data As DataObject, AllowedEffects As Long)
Data.SetData Picture1(Index).Picture, vbCFBitmap
AllowedEffects = vbDropEffectCopy
End Sub

Private Sub Timer1_Timer()
mMove.ToNewPosition Me.ScaleWidth, 0
End Sub

__________________________________________________ ______
__________________________________________________ ______

en un modulo yamado mMove introducir el siguiente code:
__________________________________________________ ______
__________________________________________________ ______

Option Explicit

'the Current X and Y position
Public curX As Single
Public curY As Single

'the last recorded X and Y position
Private lastX As Single
Private lastY As Single

'the outer move bounds of the scrollbar thingie
Private minX As Single
Private maxX As Single

'the control being moved
Private meControl As control
Private meForm As Form

'Whether the control is in the middle of being moved
Private Moving As Boolean
Private timer As timer

' Begin the move
Public Sub Begin(control As control, theform As Form, X As Single, Y As Single)
mMove.Moving = True
Set mMove.meControl = control
Set mMove.meForm = theform
mMove.lastX = X
mMove.lastY = Y
End Sub

Public Sub InProgress(X As Single, Y As Single)
If Not mMove.Moving Then Exit Sub
timer.Enabled = True

mMove.curX = X - mMove.lastX
mMove.curY = Y - mMove.lastY
End Sub

Public Sub EndIt()
mMove.Moving = False
timer.Enabled = False
End Sub

Public Sub ToNewPosition(RightBound As Integer, LeftBound As Integer)
Dim X As Single
Dim Y As Single

'Set it to the new position.
X = mMove.meControl.Left + curX
Y = mMove.meControl.Top + curY

'Make sure we don't drag it off the screen...
If X < LeftBound Then
X = LeftBound
ElseIf X > (RightBound - mMove.meControl.Width) Then
X = RightBound - mMove.meControl.Width
End If
If mMove.meControl.Top + mMove.curY < 0 Then
Y = 0
ElseIf Y > meForm.ScaleHeight - mMove.meControl.Height Then
Y = meForm.ScaleHeight - mMove.meControl.Height
End If

mMove.meControl.Move X, Y
End Sub

Public Sub Initialize(tmr As timer)
tmr.Enabled = False
tmr.Interval = 30
Set timer = tmr
End Sub

aora arrastren un archivo jpg al form o al archivo compilado.... aki tienen un code dificilisimo de encontrar i de muxo valor... no lo desperdicien.

by Cl4Ss :) email (msn): [email protected]

sscreamm2005
10-01-2003, 04:37
el ejemplo de arriba tuvo muxos fallos bajense el source de esta web (ni intenten el ejemplo de arriba que no les valdra ya que ai q acer muxas modificaciones a los controles i tal i es muxo lio es mas facil bajarce directamente el code :rolleyes: URL--->

Drag & Drop (download) (http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial11/ImageDrag2.zip)