Exemple #1
0
    // the MouseDown event for the left TextBox. This event fires when the
    // mouse is in the control's bounds and the mouse button is clicked.

    private void TextBoxLeft_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            txtLeft.SelectAll();
            //invoke the drag and drop operation
            txtLeft.DoDragDrop(txtLeft.SelectedText, DragDropEffects.Move | DragDropEffects.Copy);
        }
    }
 /// <summary>
 /// The MouseDown event of the source control is used to initiate a drag operation.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">A MouseEventArgs that contains the event data.</param>
 private void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     // Sets a reference to the control that initiated the DragDrop operation, so
     // that the target control can implement logic to handle data dragged from
     // specific controls differently.  This control reference is also used in the
     // case of a Move effect to remove the data from the source control after a drop.
     sourceControl = textBox1;
     // Record the mouse button that initiated this operation in order to allow
     // target controls to respond differently to drags with the right or left
     // mouse buttons.
     mouseButton = e.Button;
     // This initiates a DragDrop operation, specifying that the data to be dragged
     // with be the text stored in the textBox1 control.  This also specifies
     // that both Copy and Move effects will be allowed.
     textBox1.DoDragDrop(textBox1.Text, DragDropEffects.Move | DragDropEffects.Copy);
 }