I can't manage to have the following code snippet run ok.
Could you please help me?
Purpose: to insert by code a command button onto a dialog
and attach an onclick event handler to this button.
Result: the dialog is dispayed with the button.
A click on the button will give an error message: property or method will not exist.
TIA,
Philippe
Code: Select all
dim mdlg as object
' ======================================================
Sub Main
' to get a reference to Dialog1
biblio=DialogLibraries.GetByName("Standard")
oFrm=biblio.getByName("Dialog1")
' instanciate the dialog
mdlg=createUNODialog(oFrm)
' to add a button and attach an event handler
call AjoutBouton( mdlg ,"monBtn" ,3 , 3 ,1)
' show the dialog
mdlg.execute
' close the dialog
'mdlg.endExecute
End Sub
Sub AjoutBouton( dialogue as object,nomBouton as string, positionX as integer,positionY as integer)
Dim oDialogModel As Object , oButtonModel As Object
NomObj = nomBouton
oDialogModel = dialogue.Model
oButtonModel = oDialogModel.createInstance("com.sun.star.awt.UnoControlButtonModel" )
With oButtonModel
.Name = NomObj
.Label = "affecter"
.PushButtonType="STANDARD"
.Tabstop = True
.PositionX = positionX 'position horizontale
.PositionY = positionY 'position verticale
.Width = 27 'largeur
.Height = 14 'hauteur
End With
' to insert the button into the dialog
oDialogModel.insertByName( NomObj , oButtonModel )
' create a listener
oButtonControl = dialogue.getControl(NomObj)
cEventListenerName =NomObj
' oActionListener = CreateUnoListener( cEventListenerName + "_", "com.sun.star.awt.XActionListener" )
oActionListener = CreateUnoListener( "NomBouton_","com.sun.star.awt.XActionListener" )
oButtonControl.addActionListener( oActionListener )
End Sub
' ===============Event handler==========================
public sub NomBouton_dispose(e as object) ' I tried _click, _onclick but unsuccessfully!
'on error resume next
msgbox "Salut :" & e.source.model.name
end sub