IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
Paradox
Search Paradox Group:

Advanced
-Collapse +Expand Paradox To/From
To/FromCODEGuides
-Collapse +Expand Paradox Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBDesktop Data...Paradox & Ob...ObjectPAL Co...OPAL: Wicked...   Print This     
  From the September 2010 Issue of Prestwood eMag
 
Paradox OPAL: Wicked Coding Tasks:
Moving a Text Box With Your Mouse
 
Posted 16 years ago on 5/29/2008 and updated 12/27/2008
Take Away: Getting started with moving objects with the mouse.

KB101136

Enabling the user to move objects around during View Data mode is very useful. In ObjectPAL, you can enable the user to move an object around to reveal something behind it, or you can enable the user to move an object to a new location. The following example shows you how to move an object around. When you let go of the mouse button, the mouseUp event occurs and the code in it snaps the object back to its original position. You could use this technique for many tasks. For example, you could use this technique in a game to reveal answers or offer clues in an educational game.

Create a form with several text boxes on it. Give them various frames and colors.

Setup form

Add lines 3-5 to the Var window of the form.

1:  ;Form :: Var
2:  Var
3:  x,y,x1,y1,w,h  SmallInt
4:  ui UIObject
5:  sTargetClass   String
6:  endVar

Add line 3 to the Init event of the form.

1:  ;Form :: init
2:  method init(var eventInfo Event)
3:  sTargetClass = ""
4: endMethod

Add lines 8-10 to the mouseDown event of the form:

1:  ;Form :: mouseDown
2:  method mouseDown(var eventInfo MouseEvent)
3:  if eventInfo.isprefilter() then
4:  ;This code executes for each object on the form
5:
6:  else
7:  ;This code executes only for the form
8:  eventinfo.getTarget(ui)
9:  ui.getPosition(x1, y1, w, h)
10: sTargetClass = ui.class
11: endIf
12: endMethod

Add lines 3-5 and 11-17 to the mouseMove event of the form:

 1: ;Form :: mouseMove
 2: method mouseMove(var eventInfo MouseEvent)
 3: var
 4: liX, liY   LongInt
 5: endVar
 6: if eventInfo.isprefilter() then
 7: ;This code executes for each object on the form
 8:
 9: else
10: ;This code executes only for the form
11: if eventinfo.isLeftDown() and
12: sTargetClass = "Text" then
13: liX = eventinfo.x()
14: liY = eventinfo.y()
15: ui.getPosition(x, y, w, h)
16: ui.setPosition(x + liX - 400, y + liY - 400, w, h)
17: endIf
18:endIf
19:endMethod

Add line 8 to the mouseUp event of the form:

1:  ;Form :: mouseUp
2:  method mouseUp(var eventInfo MouseEvent)
3:  if eventInfo.isprefilter() then
4:  ;This code executes for each object on the form
5:
6:  else
7:  ;This code executes only for the form
8:  ui.setPosition(x1,y1,w,h)
9:  endIf
10: endMethod

Check the syntax, save the form as MOVER.FSL, and run the form. Click and drag any text box you placed on the form to move it. When you let go (mouseUp), the object snaps back to its original location.


Comments

0 Comments.
Share a thought or comment...
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1153A1
Enter key:
KB Post Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101136 Counter
7515
Since 5/29/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]