Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Dragdrop event of Richtextbox is not firing
    text
    copied!<p>I am building a simple form with only a panel with two rich text boxes, and the only functionality is to allow the user to drag and drop text between the two rich text boxes.</p> <p>Here is the code:</p> <pre><code>using System; using System.Windows.Forms; namespace Exmaple { class PanelForm : Form { private RichTextBox rtb1, rtb2; public PanelForm() { this.rtb1 = new RichTextBox(); this.rtb2 = new RichTextBox(); this.rtb1.AllowDrop = true; this.rtb2.AllowDrop = true; //this.rtb1.DragEnter += new DragEventHandler(this.rtb_DragEnter); //this.rtb1.DragDrop += new DragEventHandler(this.rtb1_DragDrop); this.rtb2.DragEnter += new DragEventHandler(this.rtb_DragEnter); this.rtb2.DragDrop += new DragEventHandler(this.rtb2_DragDrop); this.rtb2.DragOver += new DragEventHandler(this.rtb_DragOver); Panel panel = new Panel(); panel.Controls.Add(rtb1); panel.Controls.Add(rtb2); this.Controls.Add(panel); this.rtb1.Dock = DockStyle.Left; this.rtb2.Dock = DockStyle.Right; panel.Dock = DockStyle.Fill; this.Text = "Panel Form"; this.Width = 600; this.Height = 300; } private void rtb_DragEnter(object sender, DragEventArgs args) { if (args.Data.GetDataPresent(DataFormats.Rtf)) { args.Effect = DragDropEffects.Copy; } else { args.Effect = DragDropEffects.None; } } private void rtb_DragOver(object sender, DragEventArgs args) { if (args.Data.GetDataPresent(DataFormats.Rtf)) { args.Effect = DragDropEffects.Copy; } else { args.Effect = DragDropEffects.None; } } private void rtb1_DragDrop(object sender, DragEventArgs args) { this.rtb1.SelectedRtf = args.Data.GetData(DataFormats.Rtf).ToString(); } private void rtb2_DragDrop(object sender, DragEventArgs args) { this.rtb2.SelectedRtf = args.Data.GetData(DataFormats.Rtf).ToString(); } } } </code></pre> <p>The problem is, the rtb_DragEnter event is fired, but the rtb2_DragDrop is not. The allowDrop property is set to true, and in the rtb_DragEnter event the DragDropEffects is set to Copy. One more thing is, the cursor is a negative sign, why is that?</p> <p>The plateform is win7, and I am using VS2010 with .NET version 4.</p> <p>Anyone having any comment or suggestion is welcome!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload