|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
To let users drop OLE data, you use the OLEDragDrop event (this event occurs only if the objects OLEDropMode property is set to Manual = 1): Sub object_OLEDragDrop( data As DataObject, effect As Long, _ button As Integer, shift As Integer, x As Single, y As Single) Here are the parameters passed to this event handler:
Here are the possible values for the effect parameter:
To get the dragged data in the OLEDragDrop event, you use the DataObjects GetData method, which returns the data stored in the format youve selected, if there is any: DataObject.GetData ( format) The format parameter here indicates the data format and may be set to one of these values:
Lets see an example. In the previous topic, weve allowed the user to drag the text from a text box, Text1, to another text box, Text2, whose OLEDropMode property is set to Manual = 1. To place the dropped data into Text2, we just add a call to GetData to that text boxs OLEDragDrop event handler:
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
Text1.OLEDrag
End Sub
Private Sub Text1_OLECompleteDrag(Effect As Long)
MsgBox "Returned OLE effect: " & Effect
End Sub
Private Sub Text1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
Data.SetData Text1.Text, vbCFText
AllowedEffects = vbDropEffectMove
End Sub
Private Sub Text2_OLEDragDrop(Data As DataObject, Effect As Long, _
Button As Integer, Shift As Integer, X As Single, Y As Single)
Text2.Text = Data.GetData(vbCFText)
End Sub
And thats itnow run the program, as shown in Figure 28.5. When you do, you can drag the text from the text box on the left, Text1, to the text box on the right, Text2, as shown in that figure. Our OLE drag/drop example is a success.
The code for this example, oledrag.frm version 1, appears in Listing 28.2 (version 2, which is located on in the oledrag folder on this books accompanying CD-ROM, will report back to Text1 what happened when Text2 accepted the data). Listing 28.2 oledrag.frm version 1
VERSION 6.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 'Windows Default
Begin VB.TextBox Text2
Height = 495
Left = 2760
OLEDropMode = 1 'Manual
TabIndex = 1
Top = 1200
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 480
OLEDropMode = 1 'Manual
TabIndex = 0
Text = "OLE Drag!"
Top = 1200
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As _
Single, Y As Single)
Text1.OLEDrag
End Sub
Private Sub Text1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
Data.SetData Text1.Text, vbCFText
AllowedEffects = vbDropEffectMove
End Sub
Private Sub Text2_OLEDragDrop(Data As DataObject, Effect As Long, _
Button As Integer, Shift As Integer, X As Single, Y As Single)
Text2.Text = Data.GetData(vbCFText)
End Sub
OLE Drag/Drop: Reporting The Drag/Drop OutcomeWhen the user drops data into a target component during an OLE drag/drop operation, you can make sure the source component is informed of that fact with the OLECompleteDrag event: Sub object_CompleteDrag([ effect As Long]) Here, the effect parameter can take these values:
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |