wpf 修改输入框 光标_在WPF中更改鼠标拖动光标

在将文档从文件系统拖到我的表单时,我必须显示鼠标光标上拖动文件的数量 .

我已经完成了以下代码,但我无法更改拖动光标 . 请让我知道最好的方法

private void tbDisplayFileContents_PreviewDragOver(object sender, DragEventArgs args)

{

if (IsSingleFile(args) != null)

{

tbDisplayFileContents_PreviewDrop(sender, args);

}

else

{

// args.Effects = DragDropEffects.None;

}

Mouse.SetCursor(Cursors.Hand);

Icon ico = new Icon(string.Concat("1365516094_10371.ico"));

tbDisplayFileContents.Cursor = GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color());

args.Handled = true;

}

private void tbDisplayFileContents_PreviewDrop(object sender, DragEventArgs args)

{

args.Handled = true;

string files = string.Empty;

string[] fileName = IsSingleFile(args);

if (fileName == null) return;

isDrag = true;

DoEvents();

for (int i = 0; i < fileName.Length; i++)

{

if (i == 0)

{

files = string.Concat("1] ", fileName[i]);

}

else

{

int j = i + 1;

files = string.Concat(files, Environment.NewLine, j, "] ", fileName[i]);

}

}

lblfileName.Content = files;

}

private string[] IsSingleFile(DragEventArgs args)

{

if (args.Data.GetDataPresent(DataFormats.FileDrop, true))

{

string[] fileNames = args.Data.GetData(DataFormats.FileDrop, true) as string[];

if (fileNames.Length != 0)

{

if (File.Exists(fileNames[0]))

{

// At this point we know there is a single file.

return fileNames;

}

}

}

return null;

}

#endregion

#region -------Events--------

private void btnClear_Click(object sender, RoutedEventArgs e)

{

lblfileName.Content = string.Empty;

}

#endregion

private void tbDisplayFileContents_PreviewDragEnter(object sender, DragEventArgs e)

{

e.Effects = DragDropEffects.None;

}

public static void DoEvents()

{

Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,

new Action(delegate

{

Icon ico = new Icon(string.Concat("1365516094_10371.ico"));

Mouse.OverrideCursor = GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color());

}));

}

我使用了GiveFeedBack事件如下

private void tbDisplayFileContents_GiveFeedback(object sender, GiveFeedbackEventArgs e)

{

if (e.Effects == DragDropEffects.Copy)

{

e.UseDefaultCursors = false;

// Mouse.SetCursor(Cursors.Hand);

Icon ico = new Icon(string.Concat("1365516094_10371.ico"));

//Mouse.Cursor = GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color());

Mouse.SetCursor(GenerateCursor.CreateCursor(ico, true, new System.Drawing.Color()));

}

else

e.UseDefaultCursors = true;

e.Handled = true;

}

它适用于表单来形成拖动,但它不适用于从外部拖动的内容(文件),例如来自Desktop的文件 .

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值