【问题标题】:How to change the cursor shape while dragging over other controls?如何在拖动其他控件时更改光标形状?
【发布时间】:2016-12-08 02:48:30
【问题描述】:

我基本上有两个涉及拖放操作的控件。我这样做是为了启动控制:

private void controlA_MouseMove(object sender, MouseEventsArgs e)
{
  if(e.LeftButton == MouseButtonState.Pressed)
  {
    //set DataObject...datao
    DragDrop.DoDragDrop(controlB, datao, DragDropEffects.Copy | DragDropEffects.Copy;
   }
}

用户从 controlA 移到 controlB 上并继续拖动到 controlB 上的某个点。我在几个事件中尝试了以下操作,但没有成功建立一个与默认箭头不同的光标,下面有一个小框:

Mouse.OverrideCursor = Cursors.Hand;

Mouse.SetCursor(Cursors.Hand);

在 controlB 的这些事件中,发生丢弃的地方:

拖动
拖动输入
给反馈

如何在拖动 controlB 时摆脱带有小框的默认箭头?

【问题讨论】:

    标签: c# .net wpf drag-and-drop


    【解决方案1】:

    ControB_MouseEnter() 事件处理程序中设置ControlB.Cursor = Cursors.Whatever;

    您可能希望将其限制在 if(e.LeftButton == MouseButtonState.Pressed) 条件下。

    在按下MouseLeftButton 时测试MouseEnter

    【讨论】:

    • MouseEnter() 仅在未按住鼠标按钮时触发。
    猜你喜欢
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-05-09
    • 1970-01-01
    • 2012-04-24
    相关资源
    最近更新 更多