使用DragDrop方法拖放卡片

时间:2009-09-19 23:56:32

标签: c#

下面是我尝试将卡片从图片框拖到面板的代码,但它不起作用。任何人都可以帮助我。当您单击该卡并尝试移动它时,光标会发生变化(例如,当您选择文本并移动它时),但卡片不会移动,当您将其放在面板上时它不会显示。

private void Card_MouseDown(object sender, MouseEventArgs e)
{
      Card.Card source = (Card.Card)(sender);
      DoDragDrop(source,DragDropEffects.Move);
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
        if (e.Data.GetDataPresent(typeof(Card.Card)))
        {

            e.Effect = DragDropEffects.Move;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
            Card.Card dragCard = (Card.Card)sender;
            dragCard = (Card.Card)e.Data.GetData(typeof(Card.Card));

}

1 个答案:

答案 0 :(得分:1)

您的代码仅包含对鼠标指针的更改。当卡被丢弃时,你只能获得卡,然后在你的代码中不做任何事情 - 这就是为什么没有发生。

相关问题