2

我在 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
    }
4

1 回答 1

6

您必须使用此方法:

var point = flowLayoutPanel1.PointToClient(new Point(e.X, e.Y));

这会将屏幕位置坐标转换为控制一,更多信息在这里

于 2013-02-27T12:17:42.600 回答