Page 1 of 1

[Solved] [Base] Get position of a Control ListBox (Macro)

PostPosted: Thu Mar 17, 2016 12:50 pm
by bcf179en
Hello everybody,

Désolé de mon anglais

I have already managed to place some controls by programming ( ListBox and Labels )

Here is the file .odb

essai2.odb
(17.22 KiB) Downloaded 85 times


Now what I want is to affect "post-it", that is to say, to move each ListBox programmatically.
To reach my goal, I start slowly. For now, what I want is that once having placed my 20 ListBox and Labels (4 x 5) by clicking on the "New Group" button, be able to click on the ListBox and have (display) coordinates.

After making clicking a Control (ListBox), I get to see the name that I decided to give it.

Then I wanted to show just the X coordinate of control. But I am told that the getPosition method is not found. Yet for each control, I did well setPosition (Point) at the time of creation.
I do not see at all what the problem is.
For contact information for controls, I used the same procedure:

deplaceCercle.odg
(55.67 KiB) Downloaded 74 times


I wish I had an answer to my question. and I thank you even before the answer.

Cordially.

Re: [Base]-Get position of a Control ListBox (Macro)

PostPosted: Fri Mar 18, 2016 8:13 pm
by MTP
If you're looking for position information, you need the object from the DrawPage, not the Forms.

So change the assignment for oObj to
Code: Select all   Expand viewCollapse view
oObj = FindObjectByName(ThisComponent.DrawPage, oControl.Name)
and the function to
Code: Select all   Expand viewCollapse view
Function FindObjectByName(oDrawPage As Object, nomObj as String) As Object
Dim objX As Object
Dim    x As Long

For x = 0 To oDrawPage.Count - 1
  objX = oDrawPage.getByIndex(x)
  If objX.Control.Name = nomObj Then
   FindObjectByName = objX ' objet trouvé
   MsgBox objX.Control.Name
   Exit Function
  EndIf
Next x
End Function     

And now this will work:
Code: Select all   Expand viewCollapse view
MsgBox oObj.getposition.x

Re: [Base]-Get position of a Control ListBox (Macro)

PostPosted: Fri Mar 18, 2016 8:14 pm
by UnklDonald418
In your "Sub DamePosition(oEvt as Object)"

try

Code: Select all   Expand viewCollapse view
Xpos = oEvt.Source.PosSize.X

Re: [Base]-Get position of a Control ListBox (Macro)

PostPosted: Sat Mar 19, 2016 6:51 pm
by bcf179en
Hello,

Thank you.

What is the difference between

Code: Select all   Expand viewCollapse view
oEvt.X


and

Code: Select all   Expand viewCollapse view
oEvt.Source.X
.

In my opinion the first one get the position in the ListBox, yes or not?

Re: [Base]-Get position of a Control ListBox (Macro)

PostPosted: Sat Mar 19, 2016 9:20 pm
by UnklDonald418
The Event that triggers your macro is a mouse click so it reports the position of the mouse inside the control/ListBox.
Code: Select all   Expand viewCollapse view
Xpos = oEvt.X

For the ListBoxes on your form Xpos will always be somewhere between 0-189 (the Width is 190), regardless of which one you select.

whereas
Code: Select all   Expand viewCollapse view
Xpos = oEvt.Source.PosSize.X

gets the position on the form of the control/ListBox so Xpos only changes if you select a Listbox in a different column. On your form Groupe5 will report the same value for Xpos as Groupe1, but Groupe2 will be different.

[Solved][Base] Get position of a Control ListBox (Macro)

PostPosted: Mon Mar 21, 2016 3:42 pm
by bcf179en
Thank you!!!!