von Steffan » Di, 26.06.2007 10:13
Hallo Thomas,
ich hab noch mal ein bißchen geschraubt und die Sache mit der Position gelöst. Und zwar funktioniert es, indem
NACH Erstellen und
VOR der Anzeige des Dialoges im Dialogmodel die Positionseigeschaft gesetzt wird.
Code: Alles auswählen
...
REM Dialog anzeigen
oDlg.Model.PositionX=50
oDlg.Model.Positiony=50
oWin = createUnoService("com.sun.star.awt.Toolkit")
oDlg.createPeer(oWin, null)
oDlg.execute
end sub
Dementsrechend kann dies Posionzuweisung am Anfang entfallen.
Beste Grüße,
Steffan
Zum Abschluss noch der vollständige Code:
Code: Alles auswählen
dim oDlg as object
Sub CreateDialog
dim oDlgM as Object 'das Modell des Dialogs
dim oMod as Object 'nimmt jeweils das Modell der Objekte auf
dim iDlgH as integer 'Höhe des Dialoges
REM das Dialogmodell erzeugen
oDlgM = createUnoService("com.sun.star.awt.UnoControlDialogModel")
REM Eigenschaften zuweisen
with oDlgM
' .setPropertyValue("PositionX", 30)
' .setPropertyValue("PositionY", 30)
.setPropertyValue("Width", 75)
.setPropertyValue("Height", 100)
.setPropertyValue("Title", "Dynamischer Dialog")
end with
REM Textlabel erzeugen
oMod = oDlgM.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
with oMod
.setPropertyValue("Name", "Text2")
.setPropertyValue("Align", 1)
.setPropertyValue("PositionX", 10)
.setPropertyValue("PositionY", 10)
.setPropertyValue("Width", 55)
.setPropertyValue("Height", 20)
.setPropertyValue("Label", "Klick Klon-Button!")
end with
oDlgM.insertByName("Text2", oMod)
REM Button erzeugen
oMod = oDlgM.createInstance("com.sun.star.awt.UnoControlButtonModel")
with oMod
.setPropertyValue("Name", "btn")
.setPropertyValue("PositionX", 5)
.setPropertyValue("PositionY", 45)
.setPropertyValue("Width", 65)
.setPropertyValue("Height", 20)
.setPropertyValue("Label", "Abbruch" )
end with
oDlgM.insertByName("btn", oMod)
REM Button klonen (vor der Anzeige des Dialogs)
oMod = oMod.CreateClone
oMod.Setpropertyvalue("PositionY",70)
oMod.Setpropertyvalue("Name","btnClone")
oMod.SetpropertyValue("Label", "Klon-Button"
oDlgM.insertByName("btnClone", oMod)
REM Dialog ertellen
oDlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oDlg.setModel(odlgM)
REM Listener für Button und Klon
oListenerClone = CreateUnoListener("btn_", "com.sun.star.awt.XActionListener")
oControl = oDlg.getControl("btn")
oControl.addActionListener(oListenerClone)
oListenerClone = CreateUnoListener("btnClone_", "com.sun.star.awt.XActionListener")
oControl = oDlg.getControl("btnClone")
oControl.addActionListener(oListenerClone)
REM Dialog anzeigen
oDlg.Model.PositionX=50
oDlg.Model.Positiony=50
oWin = createUnoService("com.sun.star.awt.Toolkit")
oDlg.createPeer(oWin, null)
oDlg.execute
end sub
sub btnClone_actionPerformed(oEvent)
REM Button klonen bei angezeigtem Dialog
with oDlg.Model
' Dialoghöhe vergrößern
.height= .height + 25
' Button der geklont werden soll, hat den höchsten Index aller Controls im Dialog
iMax=ubound(.controlModels)
oMod2=.ControlModels(iMax).CreateClone
' Eigenschaften des neuen Buttons anpassen
oMod2.Setpropertyvalue("PositionY",.Height -30)
oMod2.Setpropertyvalue("Name","btnClone" & CStr(iMax))
oMod2.SetpropertyValue("Label", "Klon-Button " & CStr(iMax))
'Button in Dialog einfügen
.InsertByName("btnClone" & CStr(iMax), oMod2)
end with
'Listener für geklonten Button
oListenerClone = CreateUnoListener("btnClone_", "com.sun.star.awt.XActionListener")
oControl = oDlg.getControl("btnClone" & cStr(iMax))
oControl.addActionListener(oListenerClone)
End Sub
sub btn_actionPerformed(oEvent)
oDlg.EndExecute
End Sub
Hallo Thomas,
ich hab noch mal ein bißchen geschraubt und die Sache mit der Position gelöst. Und zwar funktioniert es, indem [b][u]NACH[/u][/b] Erstellen und [b][u]VOR[/u][/b] der Anzeige des Dialoges im Dialogmodel die Positionseigeschaft gesetzt wird. [code]...
REM Dialog anzeigen
oDlg.Model.PositionX=50
oDlg.Model.Positiony=50
oWin = createUnoService("com.sun.star.awt.Toolkit")
oDlg.createPeer(oWin, null)
oDlg.execute
end sub[/code]
Dementsrechend kann dies Posionzuweisung am Anfang entfallen.
Beste Grüße,
Steffan
Zum Abschluss noch der vollständige Code:[code]
dim oDlg as object
Sub CreateDialog
dim oDlgM as Object 'das Modell des Dialogs
dim oMod as Object 'nimmt jeweils das Modell der Objekte auf
dim iDlgH as integer 'Höhe des Dialoges
REM das Dialogmodell erzeugen
oDlgM = createUnoService("com.sun.star.awt.UnoControlDialogModel")
REM Eigenschaften zuweisen
with oDlgM
' .setPropertyValue("PositionX", 30)
' .setPropertyValue("PositionY", 30)
.setPropertyValue("Width", 75)
.setPropertyValue("Height", 100)
.setPropertyValue("Title", "Dynamischer Dialog")
end with
REM Textlabel erzeugen
oMod = oDlgM.createInstance("com.sun.star.awt.UnoControlFixedTextModel")
with oMod
.setPropertyValue("Name", "Text2")
.setPropertyValue("Align", 1)
.setPropertyValue("PositionX", 10)
.setPropertyValue("PositionY", 10)
.setPropertyValue("Width", 55)
.setPropertyValue("Height", 20)
.setPropertyValue("Label", "Klick Klon-Button!")
end with
oDlgM.insertByName("Text2", oMod)
REM Button erzeugen
oMod = oDlgM.createInstance("com.sun.star.awt.UnoControlButtonModel")
with oMod
.setPropertyValue("Name", "btn")
.setPropertyValue("PositionX", 5)
.setPropertyValue("PositionY", 45)
.setPropertyValue("Width", 65)
.setPropertyValue("Height", 20)
.setPropertyValue("Label", "Abbruch" )
end with
oDlgM.insertByName("btn", oMod)
REM Button klonen (vor der Anzeige des Dialogs)
oMod = oMod.CreateClone
oMod.Setpropertyvalue("PositionY",70)
oMod.Setpropertyvalue("Name","btnClone")
oMod.SetpropertyValue("Label", "Klon-Button"
oDlgM.insertByName("btnClone", oMod)
REM Dialog ertellen
oDlg = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oDlg.setModel(odlgM)
REM Listener für Button und Klon
oListenerClone = CreateUnoListener("btn_", "com.sun.star.awt.XActionListener")
oControl = oDlg.getControl("btn")
oControl.addActionListener(oListenerClone)
oListenerClone = CreateUnoListener("btnClone_", "com.sun.star.awt.XActionListener")
oControl = oDlg.getControl("btnClone")
oControl.addActionListener(oListenerClone)
REM Dialog anzeigen
oDlg.Model.PositionX=50
oDlg.Model.Positiony=50
oWin = createUnoService("com.sun.star.awt.Toolkit")
oDlg.createPeer(oWin, null)
oDlg.execute
end sub
sub btnClone_actionPerformed(oEvent)
REM Button klonen bei angezeigtem Dialog
with oDlg.Model
' Dialoghöhe vergrößern
.height= .height + 25
' Button der geklont werden soll, hat den höchsten Index aller Controls im Dialog
iMax=ubound(.controlModels)
oMod2=.ControlModels(iMax).CreateClone
' Eigenschaften des neuen Buttons anpassen
oMod2.Setpropertyvalue("PositionY",.Height -30)
oMod2.Setpropertyvalue("Name","btnClone" & CStr(iMax))
oMod2.SetpropertyValue("Label", "Klon-Button " & CStr(iMax))
'Button in Dialog einfügen
.InsertByName("btnClone" & CStr(iMax), oMod2)
end with
'Listener für geklonten Button
oListenerClone = CreateUnoListener("btnClone_", "com.sun.star.awt.XActionListener")
oControl = oDlg.getControl("btnClone" & cStr(iMax))
oControl.addActionListener(oListenerClone)
End Sub
sub btn_actionPerformed(oEvent)
oDlg.EndExecute
End Sub[/code]