就拿最简单的例子说吧,一个窗体,有两个textBox控件,一个叫txt1,另外的叫txt2现在我想求助各位帮我写出,当txt1中有文本时,我选中txt1的文本,然后用鼠标拖拽到txt2中,实现文本拖拽希望大家给出代码时能适当的给点注释,谢谢了

解决方案 »

  1.   

    private void textBox1_MouseMove(object sender, MouseEventArgs e)
            {
                if (textBox1.SelectedText != "")
                {
                    string strItem = textBox1.SelectedText;
                    //开始进行"Drag"操作
                    DoDragDrop(strItem, DragDropEffects.Copy | DragDropEffects.Move);
                }
            }        private void textBox2_DragDrop(object sender, DragEventArgs e)
            {
                string dummy = "temp";            string s = (string)e.Data.GetData(dummy.GetType());
                s = s.Substring(s.IndexOf(":") + 1).Trim();
                textBox2.Text = s;
            }        private void textBox2_DragEnter(object sender, DragEventArgs e)
            {            //判断是否目前拖动的数据是字符串,如果是,则拖动符串对目的组件进行拷贝
                if (e.Data.GetDataPresent(DataFormats.Text))
                    e.Effect = DragDropEffects.Move;
                else
                    e.Effect = DragDropEffects.None;
            }简单举个例子吧,但是触发我没想好,选中不松开左键直接拖到TEXTBOX2上能替换掉,触发还有待完善,太困了。。睡觉