Article ID: 186919
Article Last Modified on 7/1/2004
Thisform.Text1.Value=SPACE(10)
Thisform.Command1.Caption="Text To Drag"
\Icons\Misc\Eye.ico
\Cursors\H_move.cur
\Cursors\H_we.cur
Caption="Text To Drag"
OLEDragPicture="eye.ico"
WAIT WINDOW "Hello"
LPARAMETERS nButton, nShift, nXCoord, nYCoord
IF nButton=2
*This.OLEDrag(.F.)
This.OLEDrag(.T.)
ENDIF
This code checks to see if the right mouse button is down. If the right
mouse button is down, the code calls the OLEDrag method. You can call
the OLEDrag method with either true or false. The difference is shown
later in this article.
LPARAMETERS lDetectDrag
IF lDetectDrag
This.ForeColor=RGB(0,255,64)
ELSE
This.ForeColor=RGB(255,0,255)
ENDIF
The code above changes the color of the caption text of the command
button. It is included here as a visual confirmation that the method is
firing.
LPARAMETERS oDataObject, nEffect
nEffect=3
oDataObject.ClearData
oDataObject.SetData("Hello",1)
In this event code, you clear the data in the Data Object, which in this
case means that you clear the caption of the command button is from the
Data Object. Next, it sets the caption to the word "Hello." for
illustration purposes only. If you need to drop the actual command
button caption into the text box, you would not use this code. The
nEffect parameter is set to 3, which is the sum of 1 (for copy) and 2
(for move). The nEffect parameter is an output parameter that you pass
to the OLEDragOver event of the drop target. By default, it would be 7
(copy+move+link). Since this specific code example does not support
linking, nEffect is set to 3.
LPARAMETERS nEffect, eMouseCursor
DO CASE
CASE nEffect=1
eMouseCursor="H_we.cur"
CASE nEffect=2
eMouseCursor="H_move.cur"
ENDCASE
The code in this method checks the nEffect parameter. Visual FoxPro
automatically sets the nEffect parameter to either 1 or 2, depending on
whether or not the control key is depressed. The mouse cursor is then
set appropriately. Note that the use of these cursors are for
illustration purposes only.
LPARAMETERS nEffect
DO CASE
CASE nEffect=2
This.Caption="You Moved Me"
CASE nEffect=1
This.Caption="You Copied Me"
CASE nEffect=0
This.Caption="You Didn't Drop Me"
ENDCASE
This.ResetToDefault("ForeColor")
Thisform.Text1.BackColor=RGB(200,224,216)
This code checks to see if you should copy or move the text from the
command button. The OLEDragDrop event of the drop target (the text box)
sets the nEffect parameter and then passes it to the OLECompleteDrag of
the drag source (the command button). The programmer then needs to take
appropriate action in the OLECompleteDrag.
LPARAMETERS oDataObject, nEffect, nButton, nShift, ;
nXCoord, nYCoord, nState
DO CASE
CASE nState=0
This.BackColor=RGB(10,255,10)
IF oDataObject.GetFormat(1) && CF_TEXT
This.OLEDropHasData=1
This.OLEDropEffects=3 && Copy and Move
ELSE
This.OLEDropHasData=0
This.OLEDropEffects=0
ENDIF
CASE nState=1
CASE nState=2
ENDCASE
This code fires when you drag data over the text box. This sets the
nState parameter to zero. The event checks the Data Object to see if
there is text data in the object. If so, it sets the OLEDropHasData and
OLEDropEffects properties. The other cases for nState without any code
are for illustration purposes only.
LPARAMETERS oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
LOCAL nOperation
IF nShift=2 && Control is down
nOperation=1 && DropEffect_Copy
ELSE
nOperation=2 && DropEffect_Move
ENDIF
DO CASE
CASE oDataObject.GetFormat(1) && CF_TEXT
This.Value=oDataObject.GetData(1)
NODEFAULT
ENDCASE
nEffect=nOperation
This code fires when you drop data onto the text box. The first check
that takes place is for the nShift parameter. If the Control key is
down, the nEffect parameter sets to 1 for copy, otherwise it is 2 for
move. The nEffect parameter is an output parameter so it passes to the
OLECompleteDrag event of the drag source, Command1. After the check of
the nShift parameter, a check for the Data Object for text data with the
oDataObject.GetFormat(1) code occurs. If the check finds text, the Value
property of the text box changes to text data. The inclusion of the
NODEFAULT keyword here has two purposes. First, if it is not, a shortcut
menu appears when you drop the data. Based on the settings in the code
above, the menu has options for Copy Here, Move Here and Cancel. This
menu essentially does nothing as there has been no allowances made for
it in the OLECompleteDrag event of the drag source. Second, if you do
not include NODEFAULT, and select either Copy Here or Move Here from the
shortcut menu, the text you are dropping into the text box, appears
twice. "Hello Hello" is what displays. This is because you set the Value
property to "Hello" in the code and then the default drop behavior of
the text box adds the second "Hello" to the Value property.
185654 How To Starting OLE Drag and Drop In Manual Mode
184386 How To Using OLE Drag & Drop to Move Controls on a Form
185497 How To Using GridHitTest() with OLE Drag and Drop
Additional query words: kbvfp600
Keywords: kbhowto KB186919