Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I work in a Windows Form Application and would like to drag and drop a file on a RichTextBox and display its contents in the RichTextBox. While I have no problem to do this with a simple TextBox, in a RichTextBox I don't get this to work because the necessary two drag drop events are missing in the controls properties dialogbox in events in the first place.
I could find a code and have put it in Form_Load, but in the RichTextBox stays the File DragDrop still unavailable.

That's my not working code: It just doens't function errors where not occuring.

C#
this.richTextBox1.AllowDrop = true;
this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.RichTextBoxDragEnter);
this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.RichTextBoxDragDrop);


Any other ideas on how / why the RichTextBox has no DragDrop functions by default
and how to add them?
Posted

1 solution

It does: or at least in my version of VS it does! But not from the Design window, strangely...
Don't forget, to get it to work, you need to add code to your events:

C#
txtDetail.AllowDrop = true;
    txtDetail.DragEnter += txtDetail_DragEnter;
    txtDetail.DragDrop += txtDetail_DragDrop;
    }


void txtDetail_DragEnter(object sender, DragEventArgs e)
    {
    e.Effect = DragDropEffects.Copy;
    }
void txtDetail_DragDrop(object sender, DragEventArgs e)
    {
    ...
    }

If you don't set the Effect, then DragDrop will not work.
 
Share this answer
 
Comments
[no name] 29-Mar-15 13:55pm    
it still doesn't work, cry! the effect of the dragging shows a symbol of disallowment don't know I would decribe that more clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900