Ver Mensaje Individual
  #3 (permalink)  
Antiguo 29/03/2007, 01:23
Andriuuuuu
 
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!!