Solved

drag and drop - open text file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
consolidate or create a new vba code for performing tasks 5 63
change vba from autofit to 13.5 width? 4 28
Updates not working for MS Windows 7 12 152
Adding to a VBA? 6 61
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now