C#拖放技术的典型应用

在应用程序中,有时用户希望将数据从一个控件中拖到另一个控件中,此时就需要用到拖放技术。
程序开发步骤:
(1)新建一个窗体,在窗体中添加两个Label控件和两个TextBox控件,并将两个TextBox控件分别命名为txtDataTart和txtScoure。
(2)将txtDataTart文本框的AllowDrop属性设置为true。
(3)程序主要代码如下。

 1 private void txtDataTart_DragDrop(object sender, DragEventArgs e)
2 {
3  txtDataTart.Text = e.Data.GetData(DataFormats.Text).ToString();
4 }
5 private void txtDataTart_DragEnter(object sender, DragEventArgs e)
6 {
7  e.Effect = DragDropEffects.Copy;
8 }
9 private void txtScoure_MouseMove(object sender, MouseEventArgs e)
10 {
11  if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
12  {
13   string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
14   Application.StartupPath.LastIndexOf("")).LastIndexOf(""));
15   reportPath += @"sl3293dwarro.cur";
16   MyNoDropCursor = new Cursor(reportPath);
17   DragDropEffects dropEffect = this.txtScoure.DoDragDrop(this.txtScoure.Text, DragDropEffects.Copy | DragDropEffects.Link);
18 }
19 }

 

你可能感兴趣的:(C#)