Re: Kontrollfelder im Formular per Makro erstellen
Verfasst: Do, 27.09.2012 23:31
Hallo,
klar, geht, hier ein Beispiel für einen Button mit eingebautem Makro:
Kopiere den Code in Bibliothek "Standard", Modul "Module1".
Erzeuge ein leeres "Formular1"
Nur speichern musst Du noch.
klar, geht, hier ein Beispiel für einen Button mit eingebautem Makro:
Kopiere den Code in Bibliothek "Standard", Modul "Module1".
Erzeuge ein leeres "Formular1"
Nur speichern musst Du noch.
Code: Alles auswählen
sub openform_in_designmode_and_add_button
Dim oParms(1) As New com.sun.star.beans.PropertyValue
Dim aPoint As New com.sun.star.awt.Point
Dim aSize As New com.sun.star.awt.Size
oDoc = ThisComponent.getformdocuments.getbyname("Formular1")
if not isnull (oDoc.getComponent) then
odoc.opendesign
else
oDocname=oDoc.name
oParms(0).name="OpenMode"
oParms(0).value="openDesign"
oParms(1).name="ActiveConnection"
oParms(1).value=Verbindung
oFormDocs = ThisComponent.FormDocuments
odoc = oFormDocs.loadComponentFromURL(oDocname, "", 0, oParms())
endif
oPage = odoc.drawpage
s_label="Testknopf"
aPoint.x = 2000
aPoint.y = 1000
aSize.Width = 4000
aSize.Height = 1200
obutton = odoc.createInstance("com.sun.star.drawing.ControlShape")
oControlModel = odoc.createInstance( "com.sun.star.form.component.CommandButton" )
obutton.control = oControlModel
obutton.Size = aSize
obutton.Position = aPoint
obutton.Control.Label = s_label
obutton.Control.FocusOnClick=false
obutton.Control.name="cmd_Testknopf"
obutton.Control.Align=1
obutton.Control.VerticalAlign=1
obutton.AnchorType=0 'Paragraph
oPage.add(obutton)
oForm = obutton.control.parent
nIndex = oForm.Count-1 'Der Button wurde soeben eingefügt, deshalb ist es sehr wahrscheinlich, dass er das letzte Element der Controls-Liste der Form ist.
Dim oEvent as new com.sun.star.script.ScriptEventDescriptor
oEvent.ListenerType = "com.sun.star.awt.XActionListener"
oEvent.EventMethod = "actionPerformed"
oEvent.ScriptType = "Script"
oEvent.ScriptCode = "vnd.sun.star.script:Standard.Module1.Knopfgedrueckt?language=Basic&location=document"
oForm.registerScriptEvent(nIndex, oEvent)
odoc.currentcontroller.setformdesignmode(false)
end sub
Sub Knopfgedrueckt
msgbox "Knopf wurde gedrückt"
end sub