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

Creating a macro - Writing a Script - Using the API

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

Postby bcf179en » Thu Mar 17, 2016 12:50 pm

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 84 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 70 times


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

Cordially.
Last edited by bcf179en on Mon Mar 21, 2016 3:43 pm, edited 1 time in total.
LibreOffice Version: 4.2.8.2 Ubun 14.04
bcf179en
 
Posts: 3
Joined: Thu Mar 17, 2016 12:35 pm

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

Postby MTP » Fri Mar 18, 2016 8:13 pm

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
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
User avatar
MTP
Volunteer
 
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

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

Postby UnklDonald418 » Fri Mar 18, 2016 8:14 pm

In your "Sub DamePosition(oEvt as Object)"

try

Code: Select all   Expand viewCollapse view
Xpos = oEvt.Source.PosSize.X
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.8 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1355
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby bcf179en » Sat Mar 19, 2016 6:51 pm

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?
LibreOffice Version: 4.2.8.2 Ubun 14.04
bcf179en
 
Posts: 3
Joined: Thu Mar 17, 2016 12:35 pm

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

Postby UnklDonald418 » Sat Mar 19, 2016 9:20 pm

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.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.8 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1355
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby bcf179en » Mon Mar 21, 2016 3:42 pm

Thank you!!!!
LibreOffice Version: 4.2.8.2 Ubun 14.04
bcf179en
 
Posts: 3
Joined: Thu Mar 17, 2016 12:35 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests