In an application, there are times when users want to drag data from one control to another, which requires drag-and-drop technology.
Program Development Steps:
(1) Create a new form, add two label controls and two TextBox controls to the form, and name two TextBox controls respectively Txtdatatart and Txtscoure.
(2) Set the AllowDrop property of the Txtdatatart text box to true.
(3) The main code of the program is as follows.
private void txtDataTart_DragDrop(object sender, DragEventArgs e)
{
txtDataTart.Text = e.Data.GetData(DataFormats.Text).ToString();
}
private void txtDataTart_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void txtScoure_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
Application.StartupPath.LastIndexOf("")).LastIndexOf(""));
reportPath += @"sl3293dwarro.cur";
MyNoDropCursor = new Cursor(reportPath);
DragDropEffects dropEffect = this.txtScoure.DoDragDrop(this.txtScoure.Text, DragDropEffects.Copy | DragDropEffects.Link);
}}