VB.NET - drag & drop - copie d'une image

morickno Messages postés 117 Date d'inscription vendredi 22 avril 2005 Statut Membre Dernière intervention 26 juin 2007 - 22 juin 2005 à 15:46
njck671 Messages postés 31 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 juin 2005 - 29 juin 2005 à 17:41
J'ai fait un test de drag & drop d'une image.
Ca marche très bien pour le déplacement mais j'aurrai voulu
au lieu que ca déplace, que ca copie l'image. j'ai regarder dans
les questions et les codes existant mais j'ai rien trouvé.

pouvez vous m'aider

Merci

6 réponses

njck671 Messages postés 31 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 juin 2005
27 juin 2005 à 22:05
jacknjck671
si tuveux copier vers un fichier c'est avec filesystem[namespace]
sinon avec graphics[namespace] et sa fonction save,saveadd etcc
0
morickno Messages postés 117 Date d'inscription vendredi 22 avril 2005 Statut Membre Dernière intervention 26 juin 2007
28 juin 2005 à 14:10
je voi pas trops ce que tu veut dire
0
njck671 Messages postés 31 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 juin 2005
28 juin 2005 à 15:07
jacknjck671
quand tu dis que tu veux copier,c vers un fichier x, ou vers un treeview, ou quoi?
0
morickno Messages postés 117 Date d'inscription vendredi 22 avril 2005 Statut Membre Dernière intervention 26 juin 2007
29 juin 2005 à 09:05
copie vers une autre zone de ma feuille (un panel par exemple)
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
njck671 Messages postés 31 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 juin 2005
29 juin 2005 à 14:25
jacknjck671
il faut que ton panel accepte le dragdrop....
dans l'evenement dragdrop du panel,utilise la methode effect.
voici un codesample de msdn qui est livré avec whidbey, si ça peut t'aider

Private Sub ListDragTarget_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles ListDragTarget.DragDrop
' Ensures that the list item index is contained in the data.

If (e.Data.GetDataPresent(GetType(System.string))) Then

Dim item As Object = CType(e.Data.GetData(GetType(System.string)), System.Object)

' Perform drag and drop, depending upon the effect.
If (e.Effect = DragDropEffects.Copy Or _
e.Effect = DragDropEffects.Move) Then

' Insert the item.
If (indexOfItemUnderMouseToDrop <> ListBox.NoMatches) Then
ListDragTarget.Items.Insert(indexOfItemUnderMouseToDrop, item)
Else
ListDragTarget.Items.Add(item)

End If
End If
' Reset the label text.
DropLocationLabel.Text = "None"
End If
End Sub
il faudra surement que tu convertisse le string pour recuperer une url a partir de laquelle le panel choisira son image....
0
njck671 Messages postés 31 Date d'inscription dimanche 10 août 2003 Statut Membre Dernière intervention 28 juin 2005
29 juin 2005 à 17:41
jacknjck671
bon, j'ai trouvé un meilleur exemple, ouvre un nouveau projet et insere ces lignes dans la class Form1....pour l'adapter au projet auquel tu travaille, assure toi que les controles conteneurs de ton image supporte le dragdrop( tu le vois dans les proprietes, par exemple, une picture box n'a pas la propriete allowdrop, donc tu pourra pas y inserer directement des images)

Public
Class Form1



Private picture
As Image



Private pictureLocation
As Point



'PENSER A >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>Me.AllowDrop = True



Protected
Overrides
Sub OnPaint(
ByVal e
As PaintEventArgs)



MyBase.OnPaint(e)



' If there is an image and it has a location,



' paint it when the Form is repainted.



If
Not (
Me.picture
Is
Nothing)
And _



Not (
Me.pictureLocation.Equals(Point.Empty))
Then


e.Graphics.DrawImage(
Me.picture,
Me.pictureLocation)



End
If



End
Sub



Private
Sub Form1_DragDrop(
ByVal sender
As
Object, _



ByVal e
As DragEventArgs)
Handles
MyBase.DragDrop



' Handle FileDrop data.



If e.Data.GetDataPresent(DataFormats.FileDrop)
Then



' Assign the file names to a string array, in



' case the user has selected multiple files.



Dim files
As
String() =
CType(e.Data.GetData(DataFormats.FileDrop),
String())



Try



' Assign the first image to the 'picture' variable.



Me.picture = Image.FromFile(files(0))



' Set the picture location equal to the drop point.



Me.pictureLocation =
Me.PointToClient(
New Point(e.X, e.Y))



Catch ex
As Exception


MessageBox.Show(ex.Message)



Return



End
Try



End
If



' Handle Bitmap data.



If e.Data.GetDataPresent(DataFormats.Bitmap)
Then



Try



' Create an Image and assign it to the picture variable.



Me.picture =
CType(e.Data.GetData(DataFormats.Bitmap), Image)



' Set the picture location equal to the drop point.



Me.pictureLocation =
Me.PointToClient(
New Point(e.X, e.Y))



Catch ex
As Exception


MessageBox.Show(ex.Message)



Return



End
Try



End
If



' Force the form to be redrawn with the image.



Me.Invalidate()



End
Sub



Private
Sub Form1_DragEnter(
ByVal sender
As
Object, _



ByVal e
As DragEventArgs)
Handles
MyBase.DragEnter



' If the data is a file or a bitmap, display the copy cursor.



If e.Data.GetDataPresent(DataFormats.Bitmap) _



Or e.Data.GetDataPresent(DataFormats.FileDrop)
Then


e.Effect = DragDropEffects.Copy



Else


e.Effect = DragDropEffects.None



End
If



End
Sub


End
Class
'voila, en esperant que c ce que tu souhaite
0
Rejoignez-nous