从列表框拖动并删除文本两个文本框 [英] drag from listbox and drop to text two textboxes

查看:82
本文介绍了从列表框拖动并删除文本两个文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





iam从两个文本框中添加列表框中的文本。如下所示

textbox1文本是123

textbox2文本是某种文字



aded to list box1是123 sometext



现在当我拖动从列表框文本123 sometext到另外两个文本框应该删除到textbox3是123而textbox4是sometext,意味着当拖动文本和数字应该分开。

plz help



iam adding text in listbox from two textboxes.like below
textbox1 text is 123
textbox2 text is sometext

after aded to list box1 is 123 sometext

now when i drag from listbox text 123 sometext to two other textboxes it should be drop to textbox3 is 123 and textbox4 is sometext,means when drag n drop text and number should be seperated.
plz help

推荐答案

this is form1
private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                listBox1.DoDragDrop(listBox1.Items[listBox1.SelectedIndex].ToString(), DragDropEffects.Move);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void txtBox1_DragEnter(object sender, DragEventArgs e)
        {
            try
            {
                if (e.Data.GetDataPresent(DataFormats.Text))
                {
                    e.Effect = DragDropEffects.Move;
                }
                else
                {
                    e.Effect = DragDropEffects.None;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void txtBox1_DragDrop(object sender, DragEventArgs e)
        {
            txtwpAM1.Text = System.Convert.ToString(e.Data.GetData(DataFormats.Text).ToString());
        }





这是我的form2代码,用于添加项目,例如

textbox1是123和textbox2是某种文字





this is my form2 code for add items like
textbox1 is 123 and textbox2 is sometext

private void button1_Click(object sender, EventArgs e)
        {
            _form.AddListBoxItem(textBox2.Text + "D"+ " "+textBox1.Text);

            this.Close();
        }





当我从列表框项目中拖动它应该被触发123是textbox2而sometext是textbox1



when i drag from listbox item it should be fired 123 is textbox2 and sometext is textbox1


这篇关于从列表框拖动并删除文本两个文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆