von Carolin » Sa, 17.06.2006 14:35
Hallo,
danke für die schnelle Antwort.
Mein erstes Problem ist damit auch schon behoben.
Leider konnte ich mein zweites Problem noch nicht lösen.
Ich habe es noch nicht geschafft, ein Kontrollfeld zu erzeugen und dieses in mein Textdokument einzufügen.
Mein aktueller Code:
Code: Alles auswählen
Sub KontrollfeldEinfuegen
Dim oDoc as Object
Dim oTxt as Object
Dim oForm as Object 'das Formular
Dim oControl as Object 'das Kontrollfeld
Dim oDocCtl as Object 'der Dokumenten Controller
Dim oControlView as Object 'das ViewObjekt des Kontrollfeldes
Dim oControlShape as Object 'das Shape-Objekt des Kontrollfeldes
Dim oShape as Object
Dim oDraw as Object 'die Drawpage
oDoc = ThisComponent 'das Dokument
oTxt = oDoc.text
oDraw = oDoc.drawpage
oDocCtl = oDoc.getCurrentController()
'Form
oForm = oDoc.DrawPage.Forms.GetByName("Standard")
'Erzeuge das Kontrollfeld
oControl = _ oDoc.createInstance("com.sun.star.form.component.ListBox")
oControl.setPropertyValue("Name", "box1")
'Einfügen zu Forms
oForm.insertByName("box1", oControl)
'View-Objekt
oControlView = oDocCtl.getControl(oControl)
'Shape-Objekt
For i = 0 to oDraw.count-1
oShape = oDraw(i)
if HasUnoInterfaces( oShape, _ "com.sun.star.drawing.XControlShape") Then
if oShape.control.name = "box1" then
oControlShape = oShape
End if
End if
Next
'Einfügen in das Dokument ?
End Sub
Ich erzeuge mir eine Listbox, weise ihr einen Namen zu und füge sie dem Formular hinzu. Nun hole ich mir das View-Objekt und auch das Shape-Objekt, allerdings sind diese beiden Objekte null. Das klingt für mich auch recht logisch, da es die Listbox bisher nur im Formular gibt, aber im Dokument ist sie noch nicht zu sehen.
Wenn ich allerdings eine Listbox (ganz normal, ohne Makro) in mein Dokument einfüge, kann ich auf deren View- und Shape-Objekt zugreifen und diese sind nicht null.
An dieser Stelle komme ich nun nicht weiter, da ich ja um Größe/Position festzulegen das View-/Shape-Objekt benötige, aber diese ja nicht habe.
Wie lege ich nun die Größe und Position fest und schaffe es letztendlich, dass das Kontrollfeld in meinem Textdokument angezeigt wird ?
Gruß
Carolin
Hallo,
danke für die schnelle Antwort.
Mein erstes Problem ist damit auch schon behoben. :)
Leider konnte ich mein zweites Problem noch nicht lösen. :oops:
Ich habe es noch nicht geschafft, ein Kontrollfeld zu erzeugen und dieses in mein Textdokument einzufügen.
Mein aktueller Code:
[code]
Sub KontrollfeldEinfuegen
Dim oDoc as Object
Dim oTxt as Object
Dim oForm as Object 'das Formular
Dim oControl as Object 'das Kontrollfeld
Dim oDocCtl as Object 'der Dokumenten Controller
Dim oControlView as Object 'das ViewObjekt des Kontrollfeldes
Dim oControlShape as Object 'das Shape-Objekt des Kontrollfeldes
Dim oShape as Object
Dim oDraw as Object 'die Drawpage
oDoc = ThisComponent 'das Dokument
oTxt = oDoc.text
oDraw = oDoc.drawpage
oDocCtl = oDoc.getCurrentController()
'Form
oForm = oDoc.DrawPage.Forms.GetByName("Standard")
'Erzeuge das Kontrollfeld
oControl = _ oDoc.createInstance("com.sun.star.form.component.ListBox")
oControl.setPropertyValue("Name", "box1")
'Einfügen zu Forms
oForm.insertByName("box1", oControl)
'View-Objekt
oControlView = oDocCtl.getControl(oControl)
'Shape-Objekt
For i = 0 to oDraw.count-1
oShape = oDraw(i)
if HasUnoInterfaces( oShape, _ "com.sun.star.drawing.XControlShape") Then
if oShape.control.name = "box1" then
oControlShape = oShape
End if
End if
Next
'Einfügen in das Dokument ?
End Sub
[/code]
Ich erzeuge mir eine Listbox, weise ihr einen Namen zu und füge sie dem Formular hinzu. Nun hole ich mir das View-Objekt und auch das Shape-Objekt, allerdings sind diese beiden Objekte null. Das klingt für mich auch recht logisch, da es die Listbox bisher nur im Formular gibt, aber im Dokument ist sie noch nicht zu sehen.
Wenn ich allerdings eine Listbox (ganz normal, ohne Makro) in mein Dokument einfüge, kann ich auf deren View- und Shape-Objekt zugreifen und diese sind nicht null.
An dieser Stelle komme ich nun nicht weiter, da ich ja um Größe/Position festzulegen das View-/Shape-Objekt benötige, aber diese ja nicht habe.
Wie lege ich nun die Größe und Position fest und schaffe es letztendlich, dass das Kontrollfeld in meinem Textdokument angezeigt wird ?
Gruß
Carolin