Drag files from Windows Explorer

zhaozj2021-02-16  53

Here we are mainly discussed, how to drag a set of texts from the Windows Explorer, and then drag and drop them to a text box control. To illustrate this, the following procedure can use a text box control and OLEDRAGOVER and OLDROP events, and open a set of text files with the files attributes in the DataObject object and the VBCFFiles data format.

First start a new project in Visual Basic. Add a text box control to the form and set its OLEDROPMODE attribute to "Manual". Set the multiline property to true and set the scrollbars to 2-Vertical, and clear the Text property

code show as below:

Private Sub Text1_OLEDragDrop (Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single) If Data.GetFormat (vbCFFiles) ThenFor Each vfn In Data.Files' open loop file Open vfn For Input As # 1do while not Eof (1) line input # 1, linefiletext1 = text1 & linefile & vbcrlfloopclose # 1Next VFNend IFEND SUB

In the following events, compatible data formats (VBCFFILES) Private Sub Text1_oledragover (Data As DataObject, SHIFT AS INTEGER, X As Single, Y As Single, State As Integer) are detected with getFormat method. Getformat (vbcffiles) THEN 'If the data format is correct, the result of the upcoming operation notification source Effect = VBDROPEFFECTCOPY AND EFFECT' is not appropriate if the data format is not appropriate, then the Effect = VBDROPEFFECTNONEEND SUB

转载请注明原文地址:https://www.9cbs.com/read-21780.html

New Post(0)