Foros del Web » Programación para mayores de 30 ;) » .NET »

HELP! Problema con evento Drag Drop en un control personalizaoooo

Estas en el tema de HELP! Problema con evento Drag Drop en un control personalizaoooo en el foro de .NET en Foros del Web. Buenas a todos He desarrollado un control que contiene un listbox y un boton. Esta programado para actuar cuando salta el evento dragdrop sobre el ...
  #1 (permalink)  
Antiguo 28/03/2007, 09:05
 
Fecha de Ingreso: marzo-2007
Mensajes: 7
Antigüedad: 17 años, 1 mes
Puntos: 0
HELP! Problema con evento Drag Drop en un control personalizaoooo

Buenas a todos

He desarrollado un control que contiene un listbox y un boton. Esta programado para actuar cuando salta el evento dragdrop sobre el listbox. Si arrastro un archivo al listobox salta el evento.

el tema es que al insertar la dll en mi proyecto (VS2005 en una aplicacion de windows) selecciono mi control, lo pinta bien pero al ejecutarlo, intento arrastrar un archivo y no me deja.

Tiene la propiedad allowdrop=true tanto en el control como en la listbox que contiene.

He probado a crearme un listbox aparte en otro form y copiando y pegando el codigo de mi control me permite hacer dragdrop sin problemas.

Sabéis porque puede ser?

Muchas gracias de antemano! Me estoy volviendo locoooooooooooooo
  #2 (permalink)  
Antiguo 28/03/2007, 12:58
Avatar de RootK
Moderador
 
Fecha de Ingreso: febrero-2002
Ubicación: México D.F
Mensajes: 8.004
Antigüedad: 22 años, 2 meses
Puntos: 50
Re: HELP! Problema con evento Drag Drop en un control personalizaoooo

Si colocas el code que estás utilizando sería más fácil poderte ayudar.

por cierto no repetir post porfavor...

http://www.forosdelweb.com/f29/help-problema-con-evento-drag-drop-control-personalizaoooo-476855/#post1947135
http://www.forosdelweb.com/f78/help-problema-con-evento-drag-drop-control-personalizaoooo-476856/
http://www.forosdelweb.com/f29/help-problema-con-evento-drag-drop-control-personalizaoooo-476855/
http://www.forosdelweb.com/f14/help-problema-con-evento-drag-drop-control-personalizaoooo-476857/

Con una vez es suficiente...
  #3 (permalink)  
Antiguo 29/03/2007, 01:23
 
Fecha de Ingreso: marzo-2007
Mensajes: 7
Antigüedad: 17 años, 1 mes
Puntos: 0
Re: HELP! Problema con evento Drag Drop en un control personalizaoooo

buenas!

Mira te pongo el code de la clase del control de la biblioteca de controles que he creado.

Imports Microsoft.Office.Interop

Public Class ListBoxDragAndDrop
Private _rutaservidor As String
Property rutaservidor() As String
Get
Return _rutaservidor
End Get
Set(ByVal value As String)
_rutaservidor = value
End Set
End Property
Private Sub ListDragDrop_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Dim nuevoguid As Guid
Dim filestr As IO.FileStream
'Dim archivo As IO.File
Try

If (e.Data.GetDataPresent("FileName", False) And e.Data.GetDataPresent("filedrop", False)) Then
Dim fs As IO.FileStream = Nothing
Dim ms As IO.MemoryStream = Nothing
Dim rutaarchiv As String = ""
Dim nombrearchi As String = ""

Dim arraypath() As String
Try

nombrearchi = CType(e.Data.GetData(DataFormats.FileDrop), Array).GetValue(0).ToString

ListDragDrop.Items.Add(nombrearchi)

arraypath = nombrearchi.Split("\")

filestr = New IO.FileStream(nombrearchi, IO.FileMode.Open, IO.FileAccess.Read)
Dim b() As Byte = New Byte(Convert.ToInt32(filestr.Length)) {}

If IO.File.Exists(nombrearchi) = True Then
'IO.File.Create(_rutaservidor & arraypath(arraypath.Length - 1), b.Length)
If IO.File.Exists(_rutaservidor & arraypath(arraypath.Length - 1)) = False Then
IO.File.Copy(nombrearchi, _rutaservidor & arraypath(arraypath.Length - 1), b.Length)

'ListDragDrop.Items.Add("ARCHIVO: " & _rutaservidor & arraypath(arraypath.Length - 1).ToString)
ListDragDrop.Items.Add("ARCHIVO: " & nombrearchi)
MessageBox.Show("Archivo subido al servidor", "Archivo subido", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("El archivo ya existe en el servidor", "Archivo ya existe", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

End If

If Not filestr Is Nothing Then
filestr.Close()
filestr.Dispose()
filestr = Nothing
End If

Catch ex As Exception

Finally
If Not fs Is Nothing Then
fs.Close()
fs.Dispose()
fs = Nothing
End If
End Try
Else
'Esto es que no esta abierto el outlook o que esta haciendo drag desde otro sitio
Dim OL As Microsoft.Office.Interop.Outlook.Application = GetObject(, "Outlook.Application")

Dim mi As Microsoft.Office.Interop.Outlook.MailItem
Dim conta = 0
Dim rutas As String = ""

If OL.ActiveExplorer.Selection.Count = 0 Then
'Esta abierto pero no hay seleccion de outlook
Else
For Each mi In OL.ActiveExplorer.Selection()

nuevoguid = Guid.NewGuid()
If IO.File.Exists(_rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg") = False Then
mi.SaveAs(_rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg")

ListDragDrop.Items.Add("E-MAIL: " & _rutaservidor & mi.Subject.ToString.Trim.Replace(" ", "_") & nuevoguid.ToString & ".msg")
Else
MessageBox.Show("El Email ya existe en el servidor", "E-Mail ya existe", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If



Next
MessageBox.Show("Email/s subido al servidor", "Archivo subido", MessageBoxButtons.OK, MessageBoxIcon.Information)

End If

If Not mi Is Nothing Then
mi.Close(Outlook.OlInspectorClose.olDiscard)
mi = Nothing
End If

End If
Catch ex As Exception

End Try


End Sub

Private Sub ListDragDrop_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs)
Try
e.Effect = DragDropEffects.Copy
Catch ex As Exception

End Try
End Sub

Private Sub btborrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btborrar.Click
Dim selec As ListBox.SelectedObjectCollection
'Dim selecindexes As ListBox.SelectedIndexCollection

Dim arraypath() As String
Dim arrayborr As New ArrayList


Try
If ListDragDrop.SelectedItems.Count > 0 Then
selec = ListDragDrop.SelectedItems
'selecindexes = ListBox1.SelectedIndices

For i As Integer = 0 To selec.Count - 1
arraypath = Nothing
arraypath = selec(i).ToString.Split("\")

If IO.File.Exists(_rutaservidor & arraypath(arraypath.Length - 1)) Then
IO.File.Delete(_rutaservidor & arraypath(arraypath.Length - 1))
arrayborr.Add(selec(i).ToString)
MessageBox.Show("Archivo " & _rutaservidor & arraypath(arraypath.Length - 1) & "borrado del servidor")
Else
MessageBox.Show("El archivo " & _rutaservidor & arraypath(arraypath.Length - 1) & "no se encuentra en el servidor")
End If
Next
For j As Integer = 0 To arrayborr.Count - 1
ListDragDrop.Items.Remove(arrayborr(j).ToString)
Next
Else
MessageBox.Show("Tienes que seleccionar por lo menos un archivo")
End If

If Not arrayborr Is Nothing Then
arrayborr.Clear()
arrayborr = Nothing
End If
Catch ex As Exception

End Try
End Sub


End Class


Y Te pongo tb el code del archivo.designer.vb donde se definen las propiedades de los objetos.

<Global.Microsoft.VisualBasic.CompilerServices.Des ignerGenerated()> _
Partial Class ListBoxDragAndDrop
Inherits System.Windows.Forms.UserControl

'UserControl reemplaza a Dispose para limpiar la lista de componentes.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub

'Requerido por el Diseñador de Windows Forms
Private components As System.ComponentModel.IContainer

'NOTA: el Diseñador de Windows Forms necesita el siguiente procedimiento
'Se puede modificar usando el Diseñador de Windows Forms.
'No lo modifique con el editor de código.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.btborrar = New System.Windows.Forms.Button
Me.ListDragDrop = New System.Windows.Forms.ListBox
Me.SuspendLayout()
'
'btborrar
'
Me.btborrar.FlatStyle = System.Windows.Forms.FlatStyle.Popup
Me.btborrar.Image = Global.FileUploadDragDrop.My.Resources.Resources.d elete
Me.btborrar.Location = New System.Drawing.Point(570, 17)
Me.btborrar.Name = "btborrar"
Me.btborrar.Size = New System.Drawing.Size(30, 26)
Me.btborrar.TabIndex = 3
Me.btborrar.UseVisualStyleBackColor = True
'
'ListDragDrop
'
Me.ListDragDrop.AllowDrop = True
Me.ListDragDrop.BackColor = System.Drawing.SystemColors.Info
Me.ListDragDrop.Font = New System.Drawing.Font("Arial", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.ListDragDrop.ForeColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(128, Byte), Integer), CType(CType(128, Byte), Integer))
Me.ListDragDrop.FormattingEnabled = True
Me.ListDragDrop.ItemHeight = 16
Me.ListDragDrop.Location = New System.Drawing.Point(3, 3)
Me.ListDragDrop.Name = "ListDragDrop"
Me.ListDragDrop.ScrollAlwaysVisible = True
Me.ListDragDrop.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
Me.ListDragDrop.Size = New System.Drawing.Size(564, 52)
Me.ListDragDrop.TabIndex = 2
'
'ListBoxDragAndDrop
'
Me.AllowDrop = True
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), CType(CType(192, Byte), Integer), CType(CType(192, Byte), Integer))
Me.Controls.Add(Me.btborrar)
Me.Controls.Add(Me.ListDragDrop)
Me.Name = "ListBoxDragAndDrop"
Me.Size = New System.Drawing.Size(602, 60)
Me.ResumeLayout(False)

End Sub
Friend WithEvents btborrar As System.Windows.Forms.Button
Friend WithEvents ListDragDrop As System.Windows.Forms.ListBox

End Class

Gracias!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:05.