0982 0986




Visual Basic 6 Black Book:Advanced Form, Control, And Windows Registry Handling
function GetCookie (name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) { var end = document.cookie.indexOf (";", j); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(j, end)); } i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } var m1=''; var gifstr=GetCookie("UsrType"); if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; } document.write(m1+m2+m3);            Keyword Title Author ISBN Publisher Imprint Brief Full  Advanced      Search  Search Tips Please Select ----------- Components Content Mgt Certification Databases Enterprise Mgt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Prod Apps Programming Security UI Web Services Webmaster Y2K ----------- New Titles ----------- Free Archive To access the contents, click the chapter and section titles. Visual Basic 6 Black Book (Publisher: The Coriolis Group) Author(s): Steven Holzner ISBN: 1576102831 Publication Date: 08/01/98 function isIE4() { return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') ); } function bookMarkit() { var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0"; parent.location.href=url; //var win = window.open(url,"myitk"); //if(!isIE4()) // win.focus(); } Search this book:  














Previous
Table of Contents
Next




That’s all it takes—now users can move the text boxes in the dragcontrols example around as they like. The code for this example is located in the dragcontrols folder on this book’s accompanying CD-ROM.

Drag/Drop: Handling DragOver Events
When the user drags a control over a form or control, a DragOver event is triggered like this:


Sub Form_DragOver(source As Control, x As Single, y As Single, state As_
Integer)


Here are the arguments this event handler is passed:


•  source—The control being dragged.
•  x, y—Position of the mouse in the target form or control. These coordinates are set in terms of the target’s coordinate system (as set by the ScaleHeight, ScaleWidth, ScaleLeft, and ScaleTop properties).
•  state—The transition state of the control being dragged in relation to a target form or control: Enter = 0, source control is being dragged into the target; Leave = 1, source control is being dragged out of the target; Over = 2, source control has moved in the target.

Let’s see an example. Here, we’ll turn the text boxes in the dragcontrols example that we’ve developed in the previous few topics blue as the user drags a control over them. To do that, we add a DragOver event to the text boxes in the Textboxes control array:


Private Sub Textboxes_DragOver(Index As Integer, Source As Control, X As _
Single, Y As Single, State As Integer)

End Sub


Here, we simply add code to turn the text box blue when we drag another control over it:



Private Sub Textboxes_DragOver(Index As Integer, Source As Control, X As _
Single, Y As Single, State As Integer)
Textboxes(Index).BackColor = RGB(0, 0, 255)
End Sub


And that’s it—now we’re handling DragOver events, as shown in Figure 28.4.

Figure 28.4  Handling DragOver events.
OLE Drag/Drop: Dragging Data
The Testing Department is on the phone again. A lot of new word processors are allowing users to drag data from application to application—how about your new SuperDuperTextPro program? It’s not possible, you say. Yes it is, they say, use OLE drag/drop.
In OLE drag/drop operations, you can let the user drag data between controls, and even between programs. Here’s how it works: when the user presses the mouse button, you start the OLE drag operation with the OLEDrag method (this method has no parameters). This causes an OLEStartDrag event, and you are passed an object of type DataObject in that event’s handler. You use that object’s SetData method to set the data you want the user to drag:


DataObject.SetData [ data], [ format]


Here, data is a variant that holds the data you want the user to drag, and format indicates the data format, which can be one of these values:

•  vbCFText—1; text (TXT) files
•  vbCFBitmap—2; bitmap (BMP) files
•  vbCFMetafile—3; Windows metafile (WMF) files
•  vbCFEMetafile—14; enhanced metafile (EMF) files
•  vbCFDIB—8; device-independent bitmap (DIB)
•  vbCFPalette—9; color palette
•  vbCFFiles—15; list of files
•  vbCFRTF—-16639; Rich Text Format (RTF) files

You’re also passed a parameter named AllowedEffects in the OLEStartDrag event’s handler, and you need to set that parameter to one of the following values:

•  vbDropEffectNone—0; drop target cannot accept the data.
•  vbDropEffectCopy—1; drop results in a copy of data from the source to the target. (Note that the original data is unaltered by the drag operation.)
•  vbDropEffectMove—2; drop results in data being moved from drag source to drop source. (Note that the drag source should remove the data from itself after the move.)

When the user drops the data onto an appropriate target, which is a form or control with its OLEDropMode property set to Manual (= 1), an OLEDragDrop event occurs, and you are passed a DataObject in that event’s handler. To get the dragged data, you use the DataObject’s GetData method:


DataObject.GetData ( format)


The format parameter here may be set to the same values as the format parameter for SetData. Let’s see an example. In this case, we’ll add two text boxes, Text1 and Text2, to a form, and let the user drag the text from Text1 to Text2. We start at design time by placing the text “OLE Drag!” into Text1 so the user will have something to drag when the program runs.

TIP:  The user will also be able to drag the text from Text1 to any OLE-drag-enabled word processor, like Microsoft Word.

When the user presses the mouse button in Text1, then, we start the OLE drag/drop operation with the OLEDrag method:


Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As _
Single, Y As Single)

Text1.OLEDrag

End Sub


This triggers an OLEStartDrag event for Text1:


Private Sub Text1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)

End Sub


Here, we’ll let the user drag the text from the text box Text1, and we do that by placing that text into the data object passed to us in the OLEStartDrag event handler:


Private Sub Text1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)

Data.SetData Text1.Text, vbCFText
...
End Sub


We also must set the AllowedEffects parameter to the OLE drag/drop operations we’ll allow:


Private Sub Text1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)

Data.SetData Text1.Text, vbCFText
AllowedEffects = vbDropEffectMove

End Sub


And that’s it—now users can drag the text from the text box. To let them drop that text in the other text box, Text2, we’ll enable that text box for OLE drops in the next topic.
OLE Drag/Drop: Dropping Data
The testing department is on the phone again. It’s fine that you’ve allowed users to drag data from controls in your program, but how about letting them drop that data as well? Coming right up, you say.



Previous
Table of Contents
Next






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.



Wyszukiwarka

Podobne podstrony:
0982 1
0986 1
0977 0982

więcej podobnych podstron