Solved

drag and drop - open text file

Posted on 2000-03-08
4
298 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 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 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

615 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