Resize a form-field in base using a macro

Using LO 24.8.7.2
Windows 11 64-bit laptop
(using external Firebird database)

Question: Is it possible to resize/reposition a form-field (i.e. an Image) using a macro that is activated using a button on the same form?

Why resizing? Do you want to see the content of the control in a better zoom?

I would open the link/image in the app, which is provided from the system I use.
Base Guide - Displaying Images/Files

I was trying to create a very simple barchart in a base form without the need maintaining that in and copying that form a Calc graph. The image(s) is(are) just a square with a background color with could also be an empty textbox or a label. When asking this question in the internet the AI-generate answer suggests that this is possible, but the listed macro-code does not work.

Charts in reports are supported.
You can easily link spreadsheet cells and pivot tables to queries.

You could also create charts in a form. But this isn’t documented in the (old) Base Guide. It’s only part of German Base Handbuch.

Seems you really try to change the height and the width of a form field, not to show a special chart or an image with the linked application of your system.
If you got the field you could set width and height.

oField = oForm.getByName("myField")
oField.PosSize.Width = 150
oField.PosSize.Height = 50

Haven’t tested, but might be you better try which value of width and height the current field will show before:

oField = oForm.getByName("myField")
inWidth = oField.PosSize.Width
inHeight = oField.PosSize.Height
oField.PosSize.Width = 2 * inWidth
oField.PosSize.Height = 2 * inHeight

That’s why I have raised the question: the error-message received was previously and still is using your suggested code :

BASIC-runtime-fout.
Eigenschap of methode niet gevonden: PosSize."
(In English: PosSize is not found )

I tried the same for a Label-field with rhe same result…

Have tested a little bit more.
You will need the controller to get the value for PosSize:

oDoc = thisComponent
oDrawpage = oDoc.drawpage
oForm = oDrawpage.forms.getByName("Formular")
oController = oDoc.getCurrentController()
oControlView = oController.getControl(oForm.getByname("Name"))
oControlView.PosSize.Width = 300
oControlView.PosSize.Height = 40

but: This property couldn’t be changed by macro when form is opened for input data. So you couldn’t resize a form field by macro.

Got it:

Sub Size(oEvent AS OBJECT)
oDoc = thisComponent
   FOR i = 0 TO oDoc.DrawPage.Count -1
      oGraphic = oDoc.DrawPage.getByIndex(i)
      IF InStr(oGraphic.LinkDisplayName,"InputName") > 0 THEN
	   oSize = oGraphic.Size
	   oSize.Width = 3040
	   oSize.Height = 400
	   oGraphic.Size = oSize
      END IF
   NEXT
End Sub

You have to get the right object in the drawpage. Name for this object you could set by navigator - not the form navigator but the navigator started with F5. It is a graphic object. But when you change the width and the height remember: The width and the height will be given in something like “twips” (1440 twips = 2,54 cm).
I have written a little bit about this in German Base Handbuch, but haven’t published the last version with chapter “Formularfelder von der Größe an Fenstergröße anpassen”. You will get it here German Base Handbuch as a *.odt-file on the right (Bearbeitungsversionen).
FormFieldSize.odb (13.8 KB)

Thanks Robert for your quick respons.
The Sub Size code, as you listed above, works well in my form, even when using multiply label fields!
A last question would be how to repostion the fields in order get the “bottoms” of multiple fields at the same (X-)line.
I have tried to get this information from your Handbuch, but did not succeed (I am familiar with the German language quite well, thats not the problem)
So far: Herzlichen Dank

If you won’t set a special size and have multiplicated by 2, for example, you could devide by 2 to get the original. Other possibility is to save the original value for the controls in a array.

The size of the control will be set back if you open the form for next time.

Since a form document is loaded in read-only mode, we can not store any modification. I would expect that reloading the document resets all the positions and sizes.

After reading your document again I have found the correct way to change the position of a field as well.
To produce a “bar chart” however you have to take into account that the x- and y-position of a form-field present the top-left corner of the field-box. This implies that you have to subtract to new height from the old Y-position in other to synchronize the bottoms of the displayed bars.
Everything works now as I intended :+1:
Nochmals danke schön !