WPF C#拖放元素作为光标

时间:2013-07-26 08:54:31

标签: c# wpf drag-and-drop cursor adorner

我是编程的新手,我正在尝试拖放这里,我现在可以拖放但是自定义光标拖放是丑陋的,我如何拖动我作为光标拖动的元素?我在网上搜索,发现一些关于装饰的提及,但我甚至不理解代码。有没有简单或简化的更好的方法来做到这一点?

我这里有这个代码,我可以拖放(我在for循环中动态创建文本框和标签,我检索文本并将其附加到数据库中的标签:

                TextBox tbox = new TextBox();
                tbox.Width = 250;
                tbox.Height = 50;
                tbox.AllowDrop = true;
                tbox.FontSize = 24;
                tbox.BorderThickness = new Thickness(2);
                tbox.BorderBrush = Brushes.BlanchedAlmond;     
                tbox.PreviewDrop += new DragEventHandler(tbox_Drop);

                if (lstQuestion[i].Answer.Trim().Length > 0)
                {

                    wrapPanel2.Children.Add(tbox);
                    answers.Add(lbl.Content.ToString());
                    MatchWords.Add(question.Content.ToString(), lbl.Content.ToString());

                }

 Dictionary<string, string> shuffled = Shuffle(MatchWords);
        foreach (KeyValuePair<string, string> s in shuffled)
        {
            Label lbl = new Label();
            lbl.Content = s.Value;
            lbl.Width = 100;
            lbl.Height = 50;
            lbl.FontSize = 24;              
            lbl.DragEnter += new DragEventHandler(lbl_DragEnter);
          //  lbl.MouseMove += new MouseEventHandler(lbl_MouseMove);
            lbl.MouseDown +=new MouseButtonEventHandler(lbl_MouseDown);

           dockPanel1.Children.Add(lbl);
        }

我正在将标签(拖动目标)拖动到文本框(放置目标),我应该使用哪个事件以及如何编写事件以将拖动光标设置为我拖动的标签?

以下是我使用atm的事件:

        private void tbox_Drop(object sender, DragEventArgs e)
    {
        MessageBox.Show("Are you sure ? Wrong don't blame me ");
        (sender as TextBox).Text = string.Empty;

    }

    private void lbl_DragEnter(object sender, DragEventArgs e)
    {
        if (sender == e.Source)
        {
            e.Effects = DragDropEffects.None;
        }
    } 

任何解决方案或帮助都很受欢迎,我见过装饰,它让我理解实施它太复杂了。寻找一种简单易用的方法来实现这一目标。