c# - 在 Windows 窗体 c# 中进行拖放操作时,将光标保持在默认形状

标签 c# winforms

我正在 Windows 窗体中进行简单的拖放操作。每当我开始操作时,光标都会改变形状。我知道这与 DragDropEffects 直接相关,我找不到导致默认光标的选项。有人可以帮忙吗?这是代码:

a.MouseDown += new MouseEventHandler(ButtonDown);
a.DragEnter += new DragEventHandler(ButtonDragEnter);
a.AllowDrop = true;

下面是函数:

private void ButtonDown(object sender, EventArgs e)
{
    PictureBox p = (PictureBox)sender;
    ButtonClick(sender, e);
    p.DoDragDrop(p.BackColor, DragDropEffects.All);
}

private void ButtonDragEnter(object sender, DragEventArgs e)
{
    e.Data.GetFormats();
    e.Effect = DragDropEffects.None;

    Color c = new Color();
    c = (Color) e.Data.GetData(c.GetType());
    ButtonClick(sender, e,c);
}

最佳答案

好的,在这里回答了我自己的问题:

您首先需要添加一个事件以提供反馈:

  a.GiveFeedback += new GiveFeedbackEventHandler(DragSource_GiveFeedback);

这里是反馈函数:

private void DragSource_GiveFeedback(object sender, GiveFeedbackEventArgs e)
    {
        e.UseDefaultCursors = false;
    }

关于c# - 在 Windows 窗体 c# 中进行拖放操作时,将光标保持在默认形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59268563/

相关文章:

c# WinForms - 将主窗口的样式传递给对话框

c# - WinForms 打印到默认打印机,即使它不可用/连接

c# - 整数求和布鲁斯,short += short 问题

c# - 如何在 C# 中组合部分类对象?

c# - 如何检测 WinForms 面板是否滚动到末尾?

c# - 为什么 Enter 和 Space 键对按钮的行为不同?

c# - 保存相关常量的最佳实践?

c# - 如何设置 Bing map 样式?

c# - 为什么我的 WCF 服务不使用我的实体模型?

c# winforms 绑定(bind) ListBox SelectedItem 的属性