【问题标题】:How do determine if drop was exactly with right mouse button up?如何确定下降是否与鼠标右键完全一致?
【发布时间】:2015-10-13 14:24:07
【问题描述】:

我实现了简单的 wpf 拖放,它可以很好地使用鼠标左键或右键。但是我怎样才能确定 drop 是否完全是用鼠标右键呢? 我的拖放以 DragDrop.DoDragDrop 开头并以

结尾
private void OnDropChannelsCommand(DragEventArgs e)
{
    ...
}

e.KeyStates 总是 DragDropKeyStates.None。

【问题讨论】:

  • Mouse.LeftButton == MouseButtonState.Pressed 但您需要在开始拖动或拖动进入事件时处理它,并将状态存储在稍后可以访问的变量中。与Mouse.RightButton 相同。
  • 在 DragEnter 事件处理程序中,您决定如何通过分配 e.Effects 属性进行拖动。在 Drop 事件处理程序中使用该属性。
  • this

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


【解决方案1】:

最后我最终处理了 DragEnter 事件

e.KeyStates == DragDropKeyStates.RightMouseButton

检查。由于某些原因,Mouse.RightButton 被设置为 Released。

【讨论】:

    【解决方案2】:

    确定鼠标按钮的最后一点是 DragOver 事件。

    然后你可以使用类似的东西:

    if ((e.KeyState & 32) == 32) { bool alt = true; }
    if ((e.KeyState & 16) == 16) { bool mousebuttonmiddle = true; }
    if ((e.KeyState & 8) == 8) { bool control = true; }
    if ((e.KeyState & 4) == 4) { bool shift = true; }
    if ((e.KeyState & 2) == 2) { bool mousebutton2 = true; }
    if ((e.KeyState & 1) == 1) { bool mousebutton1 = true; }
    

    检查什么是什么,并将 e.Effect 确定为您想要的值。 然后您可以使用刚刚修改的 e.Effect 在 OnDrop 事件中决定要做什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-24
      • 1970-01-01
      • 2011-01-05
      • 2010-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      相关资源
      最近更新 更多