Moin,
ich mache es ähnlich wie R.
Zunächst habe ich mir vor Jahren ein Modul erstellt. In diesem stehen dann so Dinge wie:
Code: Alles auswählen
REM ***** BASIC *****
' modul : mdlDlgTools
' desc : stellt tools zum Aufbau eines Dialoges during Laufzeit
' zur Verfuegung
' author : geschu
' version: 2007
' Reihenfolge der Parameter zu den Funktionen build....
' wurden vereinheitlicht. Die Reihenfolge ist jetzt immer:
' Name -- Height -- width -- PosX -- PosY -- Title -- usw
' ------------------------------------------------------
option explicit
private function buildDialog( sDlgName as String, _
dlgHeight as Integer, dlgWidth as Integer, _
dlgPosX as integer, dlgPosY as integer, _
dlgTitle as String) as Object
dim oMod as Object
oMod = CreateUnoService("com.sun.star.awt.UnoControlDialogModel")
with oMod
.setPropertyValue("PositionX", dlgPosX)
.setPropertyValue("PositionY", dlgPosY)
.setPropertyValue("Width", dlgWidth)
.setPropertyValue("Height", dlgHeight)
.setPropertyValue("Name", sDlgName)
.setPropertyValue("Title", dlgTitle)
end with
buildDialog = oMod
end function ' buildDialog
' Hier wird ein Button erzeugt:
private sub buildButton(oDlgMod as Object, _
sButName as String, _
butHeight as Integer,butWidth as Integer, _
butPosX as integer, butPosY as integer, _
butLabel as String,Optional sTyp as String)
dim oMod as Object
oMod = oDlgMod.CreateInstance("com.sun.star.awt.UnoControlButtonModel")
with oMod
.setPropertyValue("Name",sButName)
.setPropertyValue("Align",1)
.setPropertyValue("TabIndex",1)
.setPropertyValue("PositionX",butPosX)
.setPropertyValue("PositionY",butPosY)
.setPropertyValue("Width",butWidth)
.setPropertyValue("Height",butHeight)
.setPropertyValue("Label",butLabel)
if not isMissing (sTyp) then
select case sTyp
case "OK"
.setPropertyValue("PushButtonType", com.sun.star.awt.PushButtonType.OK)
case else
.setPropertyValue("PushButtonType", com.sun.star.awt.PushButtonType.STANDARD)
end Select
end if
end with
oDlgMod.insertByname(sButName,oMod)
end sub
Aufgerufen wird das Ganze z.B. so
Code: Alles auswählen
option explicit
' the document
private oDoc as Object
' the dialog
private oDlgMasterData as Object
private oDlgModelMasterData as Object
' the buttons
private oMDNew_ as Object
private oCmdMDNew as Object
private oGetIt_ as Object
private oCmdGetIt as Object
private oMDInfo_ as Object
private oCmdMDInfo as Object
private oSaveAs_ as Object
private oCmdSaveAs as Object
' some stuff
private const DLG_MASTERDATA as String = "dlgMasterData"
private Const DIALOG_TITLE as String = "Ding Dong "
private const DIALOG_VERSION as String = "Dlg - Version 2.11.2007 by geschu"
sub debug
'Xray ThisComponent
'saveMasterData()
openDlgMasterData()
end sub
sub openDlgMasterData(Optional oDocIn as Object) on Error goto ErrorHandler
' instanziate the document
if not(isMissing(oDocIn)) then
oDoc = oDocIn
else
oDoc = ThisComponent
end if
'create the dialog
oDlgModelMasterData = mdlDlgTools.buildDialog(DLG_MASTERDATA,109,198,116,49,DIALOG_TITLE)
oDlgMasterData = CreateUnoService("com.sun.star.awt.UnoControlDialog")
oDlgMasterData.setModel(oDlgModelMasterData)
' build the controls
with mdlDlgTools
' the buttons
.buildButton(oDlgModelMasterData,"cmdMDNew", 12,40,145,8,"Neu","STANDARD")
oMDNew_ = CreateUnoListener("MDNew_","com.sun.star.awt.XActionListener")
oCmdMDnew = oDlgMasterData.getControl("cmdMDNew")
oCmdMDNew.AddActionListener(oMDNew_) ' Neu is pressed
.buildButton(oDlgModelMasterData,"cmdGetIt", 12,40,145,21,"Übernehmen","STANDARD")
oGetIt_ = CreateUnoListener("GetIt_","com.sun.star.awt.XActionListener")
oCmdGetIt = oDlgMasterData.getControl("cmdGetIt")
oCmdGetIt.AddActionListener(oGetIt_) ' übernehmen is pressed
.buildButton(oDlgModelMasterData,"cmdSaveAs",12,40,145,35,"Speichern","STANDARD")
oSaveAs_ = CreateUnoListener("SaveAs_","com.sun.star.awt.XActionListener")
oCmdSaveAs = oDlgMasterData.getControl("cmdSaveAs")
oCmdSaveAs.AddActionListener(oSaveAs_) ' SaveAs is pressed
.buildButton(oDlgModelMasterData,"cmdEnd", 12,40,145,48,"Abbrechen","OK")
' no listener is needed for this button, for ist an OK Button
.buildButton(oDlgModelMasterData,"cmdMDInfo", 12,40,145,61,"Info","STANDARD")
oMDInfo_ = CreateUnoListener("MDInfo_","com.sun.star.awt.XActionListener")
oCmdMDInfo = oDlgMasterData.getControl("cmdMDInfo")
oCmdMDInfo.AddActionListener(oMDInfo_) ' info is pressed
end with
setMessage("-----> Was möchten Sie jetzt machen? <-----")
mdlDlgMasterData.setButtonEnable("cmdSaveAs",false)
' if present set focus on control txtOwner
'oDlgMasterData.getControl("txtOwner").setFocus()
'Xray oDlgMasterData
' last but not least: display the Dialog
oWin = CreateUnoService("com.sun.star.awt.Toolkit")
oDlgMasterData.createPeer(oWin,null)
oDlgMasterData.execute()
' remove ActionListeners
oDlgMasterData.getControl("cmdMDNew").removeActionListener(oMDNew_)
oDlgMasterData.getControl("cmdGetIt").removeActionListener(oGetIt_)
oDlgMasterData.getControl("cmdSaveAs").removeActionListener(oSaveAs_)
oDlgMasterData.getControl("cmdMDInfo").removeActionListener(oMDInfo_)
exit sub
ErrorHandler:
mdlErrorMessage.setErrorMsg _
( "Error " & Err & ": " & Error$ & " (line : " & Erl & ")" & _
"in mdlDlgMasterdata.openDialog")
end sub
Achtung bitte, dies ist kein Code, der so ohne weiteres funktioniert. Es fehlt z.B das Modul mdlErrorMessage, die sub setMessage und einiges mehr. Die subs für deine anderen Steuerelemente sowie deren Listener must Du selbst erstellen. Das schaffst du. Der Code Snipsel kann Dir dabei helfen, Deine Idee zu verwirklichen. Du kannst von mir keinen weiteren Support erwarten.
Viel Spaß damit
Gruß