Bonjour à tous,
Voilà je suis relativemment débutant en C# et je fais face à mon premier problème.
Je réalise un drag & drop de l'image d'un pictureBox1 à l'intérieur du pictureBox2 et j'aimerai que lorsque je drop l'image, elle reste là où je l'ai droppé car sinon elle va se mettre dans le coin haut en gauche de la pictureBox2...
Voilà mon code complet(trouvé sur internet) :
En fait je voudrais que l'image que je copie reste aux coordonnées exactes du drop à l'intérieur du pictureBox2.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication6 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { pictureBox2.AllowDrop = true; pictureBox1.AllowDrop = true; } //Source PictureBox private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) pictureBox1.DoDragDrop(pictureBox1.Image, DragDropEffects.All); } //Target PictureBox //Drag Drop Effects private void pictureBox2_DragEnter(object sender, System.Windows.Forms.DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Bitmap)) { e.Effect = DragDropEffects.Copy; } else e.Effect = DragDropEffects.None; } //Set the image to be the dragged image. private void pictureBox2_DragDrop(object sender, System.Windows.Forms.DragEventArgs e) { if ((e.Data.GetDataPresent(DataFormats.Bitmap))) { this.pictureBox1.Image = (Bitmap)(e.Data.GetData(DataFormats.Bitmap)); } } } }
Merci![]()
Partager