[英]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;
}
}
我看過裝飾者,任何解決方案或幫助都是感激的,對於我來說實施它的方法太復雜了。 尋找一種簡單且簡化的方法來執行此操作。
您可以使用像FluidKit這樣的開放源代碼http://fluidkit.codeplex.com/
相同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.