Solved

drag and drop - open text file

Posted on 2000-03-08
4
254 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
Comment Utility
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
Comment Utility
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
Thank you very much - works perfectly.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now