KB-33026: Dragging screen objects at run time.

Question:

How can I drag screen objects with the mouse at run time?

Solution:

First of all, in order to solve this you will need to establish which version of Elipse E3 is being used. Then, you will be able to decide how to drag screen objects at run time.

From version 3.5 on, you can create a WhileRunning script on the Screen, and subsequently use  GetMouseX e GetMouseY methods to retrieve the mouse’s position. For example:

Sub Screen1_WhileRunning()
	Item("Circle1").X = FromPixelX(Application.GetMouseX())
	Item("Circle1").Y = FromPixelY(Application.GetMouseY())
End Sub

FromPixelX and FromPixelY methods convert coordinates from pixels to himetric.

NOTE: Please bear in mind that this kind of script (WhileRunning) can hinder the application’s performance, depending on the case.

As for prior versions of the software, there are two possibilities. You can:

  1. Create a Translation or Rotation Animation for the object. The downside is that the object’s limit is the animation’s path. On the other hand, the upside is that in this case the mouse will actually drag the object; or
  2. Change the object’s position via script. The upside is that can actually move the object to any position on screen.

To do so, follow these procedures:

1. Create a script in MouseDown event of the object to be dragged. Set the object’s Name property to an Internal Tag (using the tag as a global variable). For example:

      Sub Rectangle1_MouseDown(Button, ShiftState, MouseX, MouseY)
           Application.Item("InternalTag1").Value = Name
           'Saves the exact position where the object was clicked
           Application.Item("MouseX").Value = MouseX - X
          Application.Item("MouseY").Value = MouseY - Y
     End Sub

2. Create a script in MouseUp event of the screen where the object is inserted. In this script, pass the MouseUp‘s MouseY and MouseX variables that have the X and Y position of the mouse’s cursor to the X and Y properties of the object. For example:

      dim objname
      set obj = Application.Item("InternalTag1")
      objname = obj.Value

      if objname <> "" then
           Item(objname).X = MouseX - Application.Item("MouseX").Value
           Item(objname).Y = MouseY - Application.Item("MouseY").Value
          obj.Value = ""
      end if

Attached to this article is an application developed in Elipse E3 version 3.2 build 260 that illustrates the procedures described above.

Attachments:

MouseMove

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *