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
| private Point mDropOffset;
public Form1() {
InitializeComponent();
this.Etiquette.Tag = 10;
this.Etiquette2.Tag = 10;
this.AllowDrop = true; //autorisation de prendre le boutton
this.Arthur.AllowDrop = true; //autorisation d'amener le boutton sur la case
this.Etiquette.MouseDown += Etiquette_MouseDown;
this.Etiquette2.MouseDown += Etiquette2_MouseDown;
this.Arthur.DragDrop += Arthur_DragDrop;
this.Arthur.DragEnter += Arthur_DragEnter;
this.DragDrop += Arthur_DragDrop;
this.DragEnter += Arthur_DragEnter;
}
private void Etiquette_MouseDown(object sender, MouseEventArgs e) {
//boutton
//coordronnées d'origine
mDropOffset = e.Location;
this.DoDragDrop(Etiquette, DragDropEffects.All);
}
private void Etiquette2_MouseDown(object sender, MouseEventArgs e) {
//boutton2
//coordronnées d'origine
mDropOffset = e.Location;
this.DoDragDrop(Etiquette2, DragDropEffects.All);
}
private void Arthur_DragEnter(object sender, DragEventArgs e) {
//case
e.Effects = DragDropEffects.All;
}
private void Arthur_DragDrop(object sender, DragEventArgs e) {
//panel
TextBox ctl = (TextBox)sender;
//bouton
Button btn = (Button)(e.Data.GetData(typeof(Button)));
//position du bouton
btn.Location = ctl.PointToClient(new Point(e.X -
mDropOffset.X, e.Y - mDropOffset.Y));
//ajout du bouton au panel
ctl.Controls.Add(btn);
//int valeur = Convert.ToInt16(Etiquette.Tag.ToString());
//int valeur2 = Convert.ToInt16(Etiquette2.Tag.ToString());
//int resultat = valeur + valeur2;
//Arthur.Tag = valeur;
//Arthur.Text = Arthur.Tag.ToString();
}
}
} |
Partager