- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有没有一种简单的方法来确保在拖放操作完成后,MouseUp事件不会被框架吃掉并忽略?
我已经找到了描述one mechanism的博客文章,但是涉及大量的手动记账,包括状态标志,MouseMove事件,手动“鼠标离开”检查等。如果可以的话,我宁愿不必执行所有这些操作被避免。
最佳答案
我最近想将拖放功能添加到我的项目中,但并没有遇到这个问题,但是我很感兴趣,真的很想看看我是否能找到一种比您所链接页面中描述的方法更好的方法至。我希望我清楚地了解了您想做的所有事情,总的来说,我认为我以一种更加优雅和简单的方式成功地解决了该问题。
简单来说,如果您提供一些代码,对于这样的问题,那将是很好的,这样我们就可以准确地了解您要执行的操作。我之所以这样说,是因为我在解决方案中假设了一些有关您的代码的信息……所以希望它已经很接近了。
这是代码,我将在下面解释:
this.LabelDrag.QueryContinueDrag += new System.Windows.Forms.QueryContinueDragEventHandler(this.LabelDrag_QueryContinueDrag);
this.LabelDrag.MouseDown += new System.Windows.Forms.MouseEventHandler(this.LabelDrag_MouseDown);
this.LabelDrag.MouseUp += new System.Windows.Forms.MouseEventHandler(this.LabelDrag_MouseUp);
this.LabelDrop.DragDrop += new System.Windows.Forms.DragEventHandler(this.LabelDrop_DragDrop);
this.LabelDrop.DragEnter += new System.Windows.Forms.DragEventHandler(this.LabelMain_DragEnter);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void LabelDrop_DragDrop(object sender, DragEventArgs e)
{
LabelDrop.Text = e.Data.GetData(DataFormats.Text).ToString();
}
private void LabelMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.Text))
e.Effect = DragDropEffects.Copy;
else
e.Effect = DragDropEffects.None;
}
private void LabelDrag_MouseDown(object sender, MouseEventArgs e)
{
//EXTREMELY IMPORTANT - MUST CALL LabelDrag's DoDragDrop method!!
//Calling the Form's DoDragDrop WILL NOT allow QueryContinueDrag to fire!
((Label)sender).DoDragDrop(TextMain.Text, DragDropEffects.Copy);
}
private void LabelDrag_MouseUp(object sender, MouseEventArgs e)
{
LabelDrop.Text = "LabelDrag_MouseUp";
}
private void LabelDrag_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
//Get rect of LabelDrop
Rectangle rect = new Rectangle(LabelDrop.Location, new Size(LabelDrop.Width, LabelDrop.Height));
//If the left mouse button is up and the mouse is not currently over LabelDrop
if (Control.MouseButtons != MouseButtons.Left && !rect.Contains(PointToClient(Control.MousePosition)))
{
//Cancel the DragDrop Action
e.Action = DragAction.Cancel;
//Manually fire the MouseUp event
LabelDrag_MouseUp(sender, new MouseEventArgs(Control.MouseButtons, 0, Control.MousePosition.X, Control.MousePosition.Y, 0));
}
}
}
关于.net - DoDragDrop和MouseUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29177/
我有一个可以在我的窗体周围拖动的 UserControl。当控件被意外拖离我的表单并进入桌面时,我得到了第一次机会异常(例如): A first chance exception of type 'S
我真的很难在 Silverlight 4 中获得一个简单的拖放示例。 这是我所拥有的: XAML 代码隐藏 public partial c
在 WPF 中,我想使用右键单击来启动拖放。类似于 Windows 资源管理器,右键单击,稍微移动,你会得到装饰器来指示操作中的拖放。不要移动,松开按钮时会出现上下文菜单。 我已经启动了这一切,但是当
WPF DragDrop.DoDragDrop方法有 DragSource作为它的第一个参数。 有没有办法获得这个DragSource OnDrop 中的对象或其他拖放事件? 最佳答案 简短的回答是否
我已经为此苦苦挣扎了一段时间 我的应用程序包含一个 ListView ,填充了位于服务器上的文件名。 我正在尝试实现拖放功能,以便用户可以将文件从我的应用程序拖到他/她的本地计算机中。 为此,我首先将
我想知道在 Windows 窗体应用程序中调用 DoDragDrop 方法的控件是否有任何区别。 我有一个带有两个 PictureBox 控件的窗体。一个可以拖动,另一个的 AllowsDrop 属性
在类库中的定义为: 复制代码代码如下: [UIPermissionAttribute(SecurityAction.Demand, Clipboard = UIPermission
我正在将我的应用程序实现为拖动源。当我调用 DoDragDrop(Win32 调用,而不是 MFC)时,它进入模式循环,并且在 DoDragDrop 返回之前我不会在主窗口中收到重绘消息。不幸的是,如
我使用 DragDrop.DoDragDrop 将文件从我的 C# WPF 应用程序复制到 Windows 资源管理器。但是,文件的实际复制导致我的 WPF 应用程序卡住,直到复制完成。此复制操作可能
通过 DragDrop.DoDragDrop(...) 开始拖放操作后,不再触发 MouseMove 事件。我什至尝试过 AddHandler(Window.MouseMoveEvent, new M
我正在像这样拖放外部应用程序: string[] files = new string[/* */]; // get files DataObject o = new DataObject(DataF
我已经扩展了 Canvas {System.Windows.Controls} 和可拖动到 Canvas 中的项目。在拖动过程中,我有 OnDragOver 事件,当用户单击并按住鼠标中键时,我会在其
我有一个 WPF 应用程序,当拖动操作开始时,它在某些计算机上崩溃并出现 AccessViolationException。 困难在于它只发生在我们构建服务器的构建上,当我在 Visual Studi
在我的 WPF 应用程序中,我实现了拖放并将我的 PNG 图像放在 DataObject 中,然后将其传递给 DoDragDrop 方法。关于我可以放弃哪些应用程序,这似乎是偶然的。 Excel ye
我目前正在开发一个带有 MapPoint-Control 的应用程序,这让我很难过。从 mappoint 也使用的线程启动 DoDragDrop 后,我总是在几秒后收到来自 mappoint 的对话框
我的应用程序有一个简单的功能,它连接到 Excel 并在它们之间进行拖放操作。具体来说,我只是从我的应用程序中获取一些文本值,将它们拖到 Excel 中,然后放下。 这在 90% 的时间都有效,但奇怪
我是一名优秀的程序员,十分优秀!