繁体   English   中英

WPF C#拖放元素作为光标

[英]WPF C# Drag and Drop Drag Element as Cursor

我是编程新手,我想在这里进行拖放,现在可以拖放,但是要拖放的自定义光标很难看,我该如何拖动要拖动的元素作为光标? 我在网上搜索并发现一些关于装饰的提法,但我什至不理解代码。 有没有简单或简化的更好的方法来做到这一点?

我在这里有这段代码,可以拖放(我在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);
        }

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

这是我使用过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;
        }
    } 

我看过装饰者,任何解决方案或帮助都是感激的,对于我来说实施它的方法太复杂了。 寻找一种简单且简化的方法来执行此操作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM