how to compose dialog invisibly?

Is there a better order of instructions than this? The dialog does not always become visible before .execute()
I have to resize near the end anyway – maybe I should just start at .width & .height = 0 or 1?

tia,

-dave

sub tst

	dlgmdl = createunoservice("com.sun.star.awt.UnoControlDialogModel")
	with dlgmdl
		.name = "checkwriter"
		.title = "Check Writer"
		.positionx = 170
		.positiony = 70
		.width = 300
		.height = 100
	end with

	dlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
	dlg.setModel(dlgmdl)
	window = CreateUnoService("com.sun.star.awt.Toolkit")
	dlg.createPeer(window, null)

	dlg.setvisible(false)

	ctlmdl = dlgmdl.createinstance("com.sun.star.awt.UnoControlFixedTextModel")
	with ctlmdl
		.name = "HI"
		.label = "HI"
		.positionx = 10
		.positiony = 10
		.width = 20
		.height = 20
	end with

	dlgmdl.insertbyname("HI", ctlmdl)

	' insert about 30 more controls...
	' resize dialog as appropriate (varies)...

	dlg.setvisible(true)
	dlg.execute()	

end sub

Hello,

dlg.setvisible(true)
dlg.execute()   

actually do somewhat the same thing but setting visible requires using a loop. This is mostly used for displaying a GUI developed dialog in a non-modal fashion. For an example see this post → How to make non-modal dialog?

When creating a dialog using a macro is is easy to make the dialog non-modal by adding a setting to the dialog model. See answer in this post → Dialog Modal with Basic IDE, Non-Modal with documents

Using setvisible in your sample is not needed and can be deleted. Execute will display the dialog.

In the document `Open Office Macros Explained by Andrew Pitonyak, there are some routines to make setting properties and inserting controls a bit easier. PDF here → OOME. See Section 18 - Dialogs and Controls. Code mentioned is in → 18.5.2. Creating a dialog at run time

Edit 2-19-11-30:

In reply to the comment, you can set width or height of the dialog anywhere you want - even in say a listener event. Of note though, if either is set to 0 (zero), that setting set to 0 will be ignored. So the smallest setting is 1,1. Can envision on the resize to simple change the title to something like Processing... and reduce the height to 1. Add the controls then set the new size.

Using Visible to hide and reveal the dialog seems to have it’s problems. Positioning is one and hiding doesn’t always seem to work. Other things seem to crop up every so often.

If modifying the dialog is the goal, you can add and delete controls from an event handler. Re-use of the dialog creation sub to do this requires special handling of the dialog execute statement to insure it is not run multiple times.

Well, both those examples use dialogs with predefined dimensions. My problem is i would like to define the dimensions after i have added the varying number of controls, and I would like to have the dialog hidden while the controls are being added so that the dialog window will not visibly resize itself in front of my users. The macro needs to recreate the dialog with a possibly different number of controls and run it every time it is needed.

Sorry, do not see this in your question as now stated. Only see comment about resizing near end of code. Possibly further explain your needs by editing your question.

May try later to use parameters input to construction for creation depending upon requirements.

This also seems to have some implication that the dialog will change based upon something the user does in the dialog. In that case maybe use steps in a dialog.