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 DragEDrop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_MouseDown(object sender,
MouseEventArgs e)
{
DoDragDrop(sender, DragDropEffects.Move);
}
private void panel1_DragEnter(object sender,
DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
private void panel1_DragDrop(object sender,
DragEventArgs e)
{
Button b = (Button)
e.Data.GetData(typeof(Button));
//b.Location = new Point(0, 0);
// Obtendo a posição do mouse:
Point p = new Point(e.X, e.Y);
// Transformando o ponto p
// para as coordenadas do controle (Panel1)
b.Location = panel1.PointToClient(p);
panel1.Controls.Add(b);
}
}
}
Comentários