【发布时间】:2010-09-26 23:35:17
【问题描述】:
我不明白为什么尝试将文本从标准标签拖动到记事本(或任何其他接受文本的控件)不起作用。我查看了文档和示例,但没有发现问题。光标仍然是一个圆圈,有一条线穿过它,如果我注册一个反馈回调,事件总是无。创建一个标准的 Windows 窗体应用程序,删除一个标签控件并注册 MouseDown 和 MouseMove 事件我有这段代码,我调用 label1.DoDragDrop (label1, DragDropEffects.All | DragDropEffects.Link)。任何帮助将不胜感激。
这是我的表单代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DragDropLabel
{
public partial class Form1 : Form
{
Point m_ClickLocation;
bool _bDragging = false;
public Form1()
{
InitializeComponent();
}
private void OnLabelMouseDown(object sender, MouseEventArgs e)
{
m_ClickLocation = e.Location;
_bDragging = true;
}
private void OnLabelMouseMove(object sender, MouseEventArgs e)
{
if (_bDragging)
{
Point pt = e.Location;
Size dragSize = SystemInformation.DragSize;
if (Math.Abs(pt.X - m_ClickLocation.X) > dragSize.Width / 2 ||
Math.Abs(pt.Y - m_ClickLocation.Y) > dragSize.Height / 2)
{
DragDropEffects rc = label1.DoDragDrop(label1, DragDropEffects.All | DragDropEffects.Link);
_bDragging = false;
}
}
}
}
}
【问题讨论】:
标签: c# drag-and-drop label