我正在将图片框拖放到FlowlayoutPanel中,但是事件以表格形式返回该位置...我需要在FlowLayoutPanel中此位置(图片框位于FlowLayoutPanel中并在那里拖放)
public Form1()
{
InitializeComponent();
flowLayoutPanel1.AllowDrop = true;
}
private void pictureBox_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
picBox = (PictureBox)sender;
if (picBox.Image != null)
{
var dragImage = new Bitmap((Bitmap)picBox.Image, picBox.Size);
IntPtr icon = dragImage.GetHicon();
Cursor.Current = new Cursor(icon);
DoDragDrop(picBox.Image, DragDropEffects.Copy);
}
}
}
void Form1_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(Bitmap)))
e.Effect = DragDropEffects.Copy;
}
// Occurs when the user releases the mouse over the drop target
void Form1_DragDrop(object sender, DragEventArgs e)
{
MessageBox.Show("Posicao x " + e.Y + "Posicao Y " + e.Y);//reutrn the position in form, not in flowLayoutPanel
}
最佳答案
您必须使用此方法:
var point = flowLayoutPanel1.PointToClient(new Point(e.X, e.Y));
这会将屏幕位置坐标转换为控件一个,更多信息here。