0

When I try and drag label into the rich text box, the icon stays as rejected. My labels are in a panel, separate from the rich text box. How can I get the text from the label to copy into the rich text box? Right now I get the circle with a line as though I hadn't set txtText.AllowDrop to true, but I did right there at the form load.

Thanks

1 Answer 1

1

OK, I've found out that the RichTextBox doesn't have the standard drag-n-drop implementation. I has a property called EnableAutoDragDrop, just set this to true, it will handle everything automatically. You don't need any event registering for it except this one:

richTextBox1.EnableAutoDragDrop = true; //Just this even without AllowDrop = true
//RichTextBox doesn't even have DragOver event exposed, we have to cast it to Control to expose the base DragOver event
((Control)richTextBox1).DragOver += (s, e) => 
{
    e.Effect = DragDropEffects.Copy;
};

Without registering the DragOver event handler, you have to use (hold down/press) the Control key while doing drag-n-drop.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the advice, but replacing my lblWord_MouseDown event with yours yielded no change.
@AuntJamaima the default SetText("") with 1 argument set the text as Unicode format while you check for the ANSI format in the DragEnter event handler. I updated the code and it should work now.
I made your change with no difference in behavior in the application. I've now posted the entire code. The textbox is a rich text box. I have a different version of a very similar application that seems to work with a regular text box. Could that make a difference.
@AuntJamaima OK, I updated the answer, that's the problem of RichTextBox.
Thank you. I added the call in the form load and it's works, albeit differently than a regular text box for sure. Thanks very much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.