Form1 DragDrop Demonstration Program Form1 Picture4 Picture4 Picture1 Picture1 Text1 Text1 Text1 Picture2 Picture2 Text2 Text2 Text2 Picture3 Picture3 Text3 Text3 Text3 Command1 This Button Does Nothing Label1 NUse The Grey Box At The Left Of The Text Control To DragDrop The Text Control. Form_Clicku MouseX Picture1_Click Picture1_MouseDown Button| Shift MouseYI Picture1 Widthv Text1 Form_DragDrop Source TextOffset Text2_Change# Text2_DragOverk State MousePointer@ Text2_DragDropp DropIt WhichOne Action Text1_Change Picture1_DragOverO Picture2_Click Picture2_DragOver Picture1_DragDrop, Picture2_DragDrop Picture2_MouseDown< Picture2R Text2 Picture2_MouseUp Text1_DragDropy Text1_DragOver Picture3 Text3 False Visible Label1_Click SaveWidth Form_DragOver' Form_DragDrop1 TextC Overlapp Cancel CheckIt Height DestRight DestBot Form1c Picture4 Picture4_Click Picture4_DragDrop XLeft XRight YLeft Check1 Check2 Picture3_Click Picture3_DragDrop Picture3_MouseDown Text3_Change Text3_DragDropF Command1 Command1_ClickY Command1_DragDrop Label1_DragDrop Label1 @ Form_Load CurrentX CurrentY DRAGDROP DEMONSTRATION PROGRAMO Keith Funk (CIS ID 72240, 2020) Rev. 1.0 July, 1991 This program demonstrates a way to use a Picture Controll to initiate what appears to be the dragging of a Text Control. Some such method is required because Textr Controls cannot in themselves be DragDropped since they don't have a MouseDown Event associated with them.. In addition, it shows some code that prevents a control from being dropped on top of another control. T The program works like this. The user press the mouse over a picture box (say Picture1). Picture1_MouseDown saves the current cursor location then expands the widthh of the picture so that it encompasses the text box to its right (the one the user wants to drag). When he e begins dragging, it *looks* like he is actually dragging the text box. MouseDown also initiates dragging.d Every control -and- the form can react to a Drop Event. If a control detects a DragDrop, it converts the cursor X/Y co-ords (which are relative to the top, left of the control) so that they are relative to the top, left off the form and then Calls the Form's DragDrop Event.. The form's DragDrop Event calls the Overlap function to to check if any part of the dragged control covers anyy part of another control. It then Calls the Sub DropIt and either tells it to cancel the drag because of ann overlap or to move the picture control and its associated text control to the new location if there is no overlap.. There is one exception to a control not being allowed too overlap another control. The user is allowed to dragg a control and drop it on top of itself. This lets him make small adjustments to the controls position.s Sub DropIt resets the picture control's width back to its original width and then either exits if the drag is m cancelled or uses the Move command to move the picturer box and text box to the new location. A note about the Const TextOffset. The picture controls used for dragging where created with a width of 200 twips. Their associated text controls were placed soo that they overlap the picture controls by 20 twips. Thus, the offset is 180 twips. This was done so thatt only a single vertical line separates the two controls. The large picture control, the label control and thee command button are included simply to demonstrate the code that prevents overlapping controls.. ==> Location of Mouse Pointer at start of drag drop. Values are relative to the top, left corner of the control on which the mouse was pressed.o ==> Distance between the left edge of a pictured control and the left edge of its associated text control. Picture1_MouseDown ==> Save the current location of the cursor. ==> Expand the picture control to encompass itss associated text control, so it looks to the user like he is dragging the text control.o ==> Initiate dragging. Text2_DragDrop DropIt This routine is called by Form1_DragDrop. It shrinks the picture control back to its original width. If the requested Action is "OK" then it Moves the picture control and its associated text control to the new loaction. If the Action is "Cancel", the Move is not performed.. Picture1& Cancel ==> Put the top, left corner of theh control in the same position relative to the cursor as it was before the move.s Picture2& Cancel Picture3& Cancel Picture1_DragDrop Picture2_DragDrop Picture2_MouseDown Text1_DragDrop Form_DragDrop The DragDrop Procs for *all* controls call this routine. Before doing so, these Procs convert their Mouse X/Y co-ords so that they are relative to the top, left corner of the *form*.a This routine calls the Overlap function for each control on the form to see if the control being moved overlaps the control. If it does, the DragDrop is cancelled. AA special case is the text controls that can be DragDropped. They can be dropped on themselves. This routine then calls the routine DropIt which performss the Move.. Cancel Cancel Cancel Cancel Cancel Cancel ==> Don't check for overlap if the Source controlh is the picture control associated with thet destination text control. That is, let thee user DragDrop a control on itself. Picture1 Cancel Picture2 Cancel Picture3 Cancel Overlap This function checks if any part of the Source control (the one being DragDropped) overlaps any part of another control. If it does, then the function returns True. Otherwise it returns False.. ==> Allow a picture to be dropped on itself. ==> Top left and top right of the Source control.- ==> Check if the top edge of source intersects the left edge of dest.e => top left of Source. - Check if the top,left corner of the source isu inside the dest.h - Check if the bottom edge of source intersectse the left edge of dest.o - Check if the bottom,left corner of the sourcet is inside the dest. ==> This routine determine if two lines interest.e ==> This routine checks if a point is inside a rectangle. Picture4_DragDrop Cancel# Picture3_DragDrop Picture3_MouseDown Text3_DragDrop Command1_DragDrop Label1_DragDrop ==> X + Label1.Left and Y + Label1.Top are used to convert the cursor location from being relative to the control's top, left corner to being relative to the form's top, left corner because that's the X/Y that the Move command (see DropItD Sub) requires. Form_Load ==> Let the user know what the square at the top, right of the form is. Picture Control"u