我找到了解決辦法。你需要繼承TextBox和覆蓋onmousedown事件和WndProc的:
public class DragTextBox : TextBox
{
private string dragText;
private const int WM_LBUTTONDOWN = 0x201;
protected override void OnMouseDown(MouseEventArgs e)
{
if (dragText.Length > 0)
{
SelectionStart = Text.IndexOf(dragText);
SelectionLength = dragText.Length;
DoDragDrop(dragText, DragDropEffects.Copy);
SelectionLength = 0;
}
base.OnMouseDown(e);
}
protected override void WndProc(ref Message m)
{
if ((m.Msg == WM_LBUTTONDOWN))
dragText = SelectedText;
base.WndProc(ref m);
}
}
原始代碼作者後here
這應該工作。謝謝! – rotman 2012-01-11 14:43:31