Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

drag and drop - open text file

Posted on 2000-03-08
4
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 200 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 28

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

705 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