C# 在WPF中更改鼠标拖动光标

C# 在WPF中更改鼠标拖动光标,c#,wpf,mouse-cursor,C#,Wpf,Mouse Cursor,在将文档从文件系统拖动到表单时,我必须在鼠标光标上显示被拖动的文件数 我已经完成了以下代码,但我无法更改拖动光标。请让我知道最好的方法 private void tbDisplayFileContents_PreviewDragOver(object sender, DragEventArgs args) { if (IsSingleFile(args) != null) { tbDisplayFileContents_P

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

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

    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());
        }));
    }
private void tbDisplayFileContents\u PreviewDragOver(对象发送方,DragEventArgs参数)
{
如果(IsSingleFile(args)!=null)
{
tbDisplayFileContents\u PreviewDrop(发送方,参数);
}
其他的
{
//args.Effects=DragDropEffects.None;
}
鼠标.SetCursor(光标.Hand);
Icon ico=新图标(string.Concat(“1365516094_10371.ico”);
tbDisplayFileContents.Cursor=GenerateCursor.CreateCursor(ico,true,new System.Drawing.Color());
args.Handled=true;
}
私有void tbDisplayFileContents\u PreviewDrop(对象发送方、DragEventArgs参数)
{
args.Handled=true;
string files=string.Empty;
字符串[]文件名=IsSingleFile(args);
如果(fileName==null)返回;
isDrag=true;
DoEvents();
for(int i=0;i
我使用的反馈事件如下

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; } 私有void tbDisplayFileContents\u GiveFeedback(对象发送者,GiveFeedbackEventArgs e) { if(e.Effects==DragDropEffects.Copy) { e、 UseDefaultCursors=false; //鼠标.SetCursor(光标.Hand); Icon ico=新图标(string.Concat(“1365516094_10371.ico”); //Mouse.Cursor=GenerateCursor.CreateCursor(ico,true,new System.Drawing.Color()); SetCursor(GenerateCursor.CreateCursor(ico,true,new System.Drawing.Color()); } 其他的 e、 UseDefaultCursors=true; e、 已处理=正确; } 它适用于窗体到窗体的拖动,但不适用于从窗体外部拖动的内容(文件),例如从桌面拖动的文件。

我错过了代码中的事件,该事件用于在拖放操作时修改鼠标光标。

我错过了代码中的事件,用于在拖放操作时修改鼠标光标