Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Drag and Drop
Message
From
06/05/2005 04:02:45
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
05/05/2005 18:55:21
Fabian Borghi
Xenon Information Technology
Itaparica, Brazil
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP1
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01011467
Message ID:
01011520
Views:
18
>Hello everybody:
>
>I can't make a drag and drop in a image, when i put set step on in a drag method the drag function well, but if i don't put set step, the drag don't function, what happend?
>
>The DragMode is set to Automatic but if i change to manual the drag don't fuction
>
>Drag Method:
>LPARAMETERS nAction
>SET STEP ON
>IF nAction = 2
> thisform.image1.Move(x_top,x_left,10,10)
>endif
>
>DragDrop Method:
>LPARAMETERS oSource, nXCoord, nYCoord
>PUBLIC x_top,x_left
>x_top = nXCoord
>x_left = nyCoord
>thisform.image1.Drag(2)
>
>DragOver Method:
>LPARAMETERS oSource, nXCoord, nYCoord, nState
>thisform.image1.Drag(1)
>
>Thanks in advance !!!

Fabian,
Below codes might help.
1) This one uses regular drag&drop
o = Createobject('form1')
o.Show(1)
Define Class form1 As Form
  Add Object myroom As room With Name = "Room1"
  Add Object myroom As room With Name = "Room2", Top = 110
  Add Object bed1 As bed With Left = 120, Top= 10, BackColor=0x0000FF
  Add Object bed2 As bed With Left = 120, Top= 20, BackColor=0x00FFFF
  Add Object bed3 As bed With Left = 120, Top= 30, BackColor=0xFF00FF
  Add Object bed4 As bed With Left = 120, Top= 40, BackColor=0xFFFF00

  Procedure DragDrop
    Lparameters oSource, nXCoord, nYCoord
    oSource.Top = nYCoord - oSource.YCoord
    oSource.Left = nXCoord - oSource.XCoord
  Endproc
Enddefine

Define Class bed As Container
  Height = 5
  Width = 10

  Procedure MouseDown
    Lparameters nButton, nShift, nXCoord, nYCoord
    If nButton = 1
      This.Drag(1)
    Endif
  Endproc

  Procedure RightClick
    Set Message To This.Tag
  Endproc
Enddefine

Define Class room As Container
  Height = 100
  Width = 100
  Procedure DragDrop
    Lparameters oSource, nXCoord, nYCoord
    oSource.Tag = This.Name
    oSource.Move(nXCoord, nYCoord)
  Endproc
Enddefine
2) This one uses OleDrag&Drop. You can drag & drop from Treeview on to Treeview itself or on to grid:
oForm = Createobject('myForm')
oForm.Show(1)

Define Class myForm As Form
  Height = 300
  Width = 470
  DoCreate=.T.
  DataSession=2
  nxtwips = .F.
  nytwips = .F.

  Add Object myTree As OleControl With ;
    Top = 0, ;
    Left = 0, ;
    Height = 300, ;
    Width = 200, ;
    Name = "myTree", ;
    OleClass = 'MSComCtlLib.TreeCtrl'

  Add Object myGrid As myGrid With ;
    Top = 0, ;
    Left = 220, ;
    Height = 300, ;
    Width = 250, ;
    Name = "myGrid"

  Procedure pixeltotwips
  *-- Code for PixelToTwips method
  Local liHWnd, liHDC, liPixelsPerInchX, liPixelsPerInchY
  #Define cnLOG_PIXELS_X 88
  #Define cnLOG_PIXELS_Y 90
  #Define cnTWIPS_PER_INCH 1440

  * Declare some Windows API functions.
  Declare Integer GetActiveWindow In WIN32API
  Declare Integer GetDC In WIN32API Integer iHDC
  Declare Integer GetDeviceCaps In WIN32API Integer iHDC, Integer iIndex

  * Get a device context for VFP.
  liHWnd = GetActiveWindow()
  liHDC = GetDC(liHWnd)

  * Get the pixels per inch.
  liPixelsPerInchX = GetDeviceCaps(liHDC, cnLOG_PIXELS_X)
  liPixelsPerInchY = GetDeviceCaps(liHDC, cnLOG_PIXELS_Y)

  * Get the twips per pixel.
  Thisform.nxtwips = ( cnTWIPS_PER_INCH / liPixelsPerInchX )
  Thisform.nytwips = ( cnTWIPS_PER_INCH / liPixelsPerInchY )
  Return
Endproc

  Procedure Load
  Create Cursor myTest (myID i, myType c(20))
  For ix = 1 To 20
    Insert Into myTest (myID,myType) Values (ix,Sys(2015))
  Endfor
  Locate
  This.pixeltotwips()
Endproc

  Procedure myTree.Init
  #Define tvwFirst	0
  #Define tvwLast	1
  #Define tvwNext	2
  #Define tvwPrevious	3
  #Define tvwChild	4

  With This
    .linestyle =1
    .labeledit =1
    .indentation = 5
    .PathSeparator = '\'
    .Scroll = .T.
    .OLEDragMode = 1
    .OLEDropMode = 1

    For ix=1 To 3
      .Nodes.Add(,tvwFirst,"root"+Ltrim(Str(ix)),'Main node '+Ltrim(Str(ix)))
      For jx=1 To 4
        .Nodes.Add("root"+Ltrim(Str(ix)),tvwChild,;
          "child"+Ltrim(Str((ix-1)*4+jx)),;
          'Child '+Ltrim(Str(jx))+' of '+Ltrim(Str(ix)))
      Endfor
    Endfor
  Endwith
Endproc

  Procedure myTree.MouseDown
  *** ActiveX Control Event ***
  Lparameters Button, Shift, x, Y
  With Thisform
    oHitTest = This.HitTest( x * .nxtwips, Y * .nytwips )
    If Type("oHitTest")= "O" And !Isnull(oHitTest)
      This.SelectedItem = oHitTest
    Endif
  Endwith
  oHitTest = .Null.
Endproc

  Procedure myTree.OLEDragOver
  *** ActiveX Control Event ***
  Lparameters Data, effect, Button, Shift, x, Y, state
  oHitTest = This.HitTest( x * Thisform.nxtwips, Y * Thisform.nytwips )
  If Type("oHitTest")= "O"
    This.DropHighlight = oHitTest
    If !Isnull(oHitTest)
      If Y <= This.Top + 150 	And Type('oHitTest.Previous')='O'	 And !Isnull(oHitTest.Previous)
        oHitTest.Previous.EnsureVisible
      Endif
      If Y >= This.Top + This.Height - 150 And Type('oHitTest.Next')='O' And !Isnull(oHitTest.Next)
        oHitTest.Next.EnsureVisible
      Endif
    Endif
  Endif
Endproc

  Procedure myTree.OLEDragDrop
  *** ActiveX Control Event ***
  Lparameters Data, effect, Button, Shift, x, Y
  #Define tvwChild	4
  With This
    If Data.GetFormat(1)	And ;
        type(".DropHighLight") = "O" And !Isnull(.DropHighlight) &&CF_TEXT
      loTarget = .DropHighlight
      .Nodes.Add(loTarget.Key,tvwChild,;
        Sys(2015),;
        Data.GetData(1))
    Endif
  Endwith
  This.DropHighlight = .Null.
Endproc
Enddefine

Define Class myGrid As Grid
  OLEDropMode = 1
  OLEDragMode = 1

  Procedure OLEStartDrag
  Lparameters oDataObject, nEffect
  With This
    .OLEDropMode = 0
    Amouseobj(arrMouse,1)
    lnActiveRow = Ceiling( ;
      ( arrMouse[4] - (.Top + .HeaderHeight) ) / .RowHeight )
    .ActivateCell(lnActiveRow,2)
  Endwith
  oDataObject.SetData(myTest.myType,1)
Endproc

  Procedure OLECompleteDrag
  Lparameters nEffect
  This.OLEDropMode = 1
Endproc

  Procedure OLEDragOver
  Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord, nState
  With This
    lnActiveRow = Ceiling( ;
      ( nYCoord - (.Top + .HeaderHeight) ) / .RowHeight )
    .ActivateCell(lnActiveRow,2)
  Endwith
Endproc

  Procedure OLEDragDrop
  Lparameters oDataObject, nEffect, nButton, nShift, nXCoord, nYCoord
  If oDataObject.GetFormat(1)
    With This
      .Columns(2).Text1.Value = oDataObject.GetData(1)
    Endwith
  Endif
Endproc
Enddefine
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform