Dragdrop of RichTextBox

Source: Internet
Author: User

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  ;}} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.