[英]WPF C# Drag and Drop Drag Element as Cursor
i am new to programming and i am trying to do a drag and drop here , i can drag and drop now but the custom cursor to drag and drop is ugly , how do i drag the element that i am draging as the cursor? 我是编程新手,我想在这里进行拖放,现在可以拖放,但是要拖放的自定义光标很难看,我该如何拖动要拖动的元素作为光标? i search online and found some mentioning about adorner but i don't even understand the codes .
我在网上搜索并发现一些关于装饰的提法,但我什至不理解代码。 Is there any simple or simplified and better way to do this?
有没有简单或简化的更好的方法来做到这一点?
I have this code here that i can drag and drop ( i dynamically created textbox and label in a for loop , i retrieve the text and append it to label from a database : 我在这里有这段代码,可以拖放(我在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);
}
I am dragging labels(drag target) into textbox( drop target ) , which event should i use and how i write the events to set the drag cursor to the labels that i am dragging? 我将标签(拖动目标)拖到textbox(放置目标)中,应该使用哪个事件,以及如何编写事件以将拖动光标设置为要拖动的标签?
Here are the events i have used atm : 这是我使用过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;
}
}
Any solutions or help is appreciated , I've seen adorner , its way too complicated for me to understand to implement it . 我看过装饰者,任何解决方案或帮助都是感激的,对于我来说实施它的方法太复杂了。 Looking for a simple and simplified way to do this .
寻找一种简单且简化的方法来执行此操作。
You can use opensource like FluidKit http://fluidkit.codeplex.com/ 您可以使用像FluidKit这样的开放源代码http://fluidkit.codeplex.com/
Tutorials for the same http://blog.pixelingene.com/2006/11/drag-drop-with-attached-properties http://blog.pixelingene.com/2006/11/drag-drop-with-attached-properties-part-2 http://blog.pixelingene.com/2006/12/drag-drop-with-attached-properties-part-3 http://blog.pixelingene.com/2006/12/drag-drop-with-attached-properties-part-4 http://blog.pixelingene.com/2007/07/making-the-scrollbar-work-with-dragdropmanager http://blog.pixelingene.com/2007/11/improved-dragdropmanager-source-code 相同http://blog.pixelingene.com/2006/11/drag-drop-with-attached-properties的教程http://blog.pixelingene.com/2006/11/drag-drop-with-attached-properties -part-2 http://blog.pixelingene.com/2006/12/drag-drop-with-attached-properties-part-3 http://blog.pixelingene.com/2006/12/drag-drop-with -attached-properties-part-4 http://blog.pixelingene.com/2007/07/making-the-scrollbar-work-with-dragdropmanager http://blog.pixelingene.com/2007/11/improved-dragdropmanager -源代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.