Solved

drag and drop - open text file

Posted on 2000-03-08
4
275 Views
Last Modified: 2009-07-29
I have a MDI form and a child form with a Rich text box in it.  I would like to be able to drag a file into the empty space of the MDI form and open the text file in the Rich text control.

How do I open a text file by dragging the icon into my MDI form?

Any Ideas?
0
Comment
Question by:kyrakin
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Ark earned 50 total points
ID: 2598892
Hi

MDIForm code

Private Sub MDIForm_Load()
   Me.OLEDropMode = vbOLEDropManual
End Sub

Private Sub MDIForm_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  If Data.GetFormat(vbCFFiles) = True Then
    Dim sFileName$
    sFileName = Data.Files(1)
    On Error GoTo invalidFile
    Form1.RichTextBox1.LoadFile sFileName, rtfRTF
  End If
  Exit Sub
invalidFile:
  MsgBox "Invalid File Format", vbCritical
End Sub

Private Sub MDIForm_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  If Data.GetFormat(vbCFFiles) Then
    Effect = vbDropEffectMove And Effect
  Else
    Effect = vbDropEffectNone
  End If
End Sub

Cheers
0
 
LVL 4

Expert Comment

by:TigerZhao
ID: 2598900
0
 
LVL 27

Expert Comment

by:Ark
ID: 2598958
TigerZhao: Yes, it's possible to subclass MDIForm and loop for WM_DROPFILES message. If you want to study subclassing and use only pure API code, it's OK. But if you need simple code - VB itself already have _OLEDrag... events. Place your code at these events and you need no subclassing. It's the same if you want to subclass window or control to loop for WM_LBUTTONDOWN instead of using appropriate event for this form/control

Cheers
0
 

Author Comment

by:kyrakin
ID: 2600318
Thank you very much - works perfectly.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question