Reference: http://blog.iordanov.info /? P = 32
To implement the drag-and-drop function of RichTextBox, you only need to set enableautodragdrop = true to automatically implement it, which is very simple. However, it is a little complicated to implement some personalized control.
What I need to implement is: If you drag and drop a file in, you do not want to embed an object connection by default, but upload the file. In other cases, you just want to use the default method.
First, you must set allowdrop = true. However, the event settings of the vs control do not contain the dragenter and dragdrop events and can only be manually written.Code.
// Add an event
Private Void Addrtb1event () {rtb1.allowdrop = True ; Rtb1.dragenter + = New Drageventhandler (rtbw.dragenter); rtb1.dragdrop + = New Drageventhandler (rtbw.dragdrop );} Private Void Rtb1_dragenter ( Object Sender, drageventargs e) {e. Effect = Dragdropeffects. Copy; string [] supportedformats = E. Data. getformats ( True ); If (Supportedformats! =Null ) {List < String > Sflist = New List < String > (Supportedformats ); If (Sflist. Contains (dataformats. filedrop. tostring () {rtb1.enableautodragdrop = False ;} Else {Rtb1.enableautodragdrop = True ;}}} Private Void Rtb1_dragdrop ( Object Sender, drageventargs e) {string [] supportedformats = E. Data. getformats ( True ); If (Supportedformats! = Null ) {List < String > Sflist = New List < String > (Supportedformats ); If (Sflist. Contains (dataformats. filedrop. tostring ())){ String [] Filelist = ( String []) (System. array) E. Data. getdata (dataformats. filedrop )); Foreach ( String FilenameIn Filelist) {MessageBox. Show (filename) ;}} rtb1.enableautodragdrop = True ;}}