LibreOfficeDev 7.4 Hjelp
Eksempla nedanfor skildrar eit nytt dialogvindauge kalla «Dialog1». Bruk kontrollelementa på verktøylinja Verktøykasse i dialogredigeringa for å lage dialogvindauget og leggja til følgjande kontrollelement: ein Avkryssingsboks kalla «CheckBox1», eit Etikettfelt kalla «Label1», ein Knapp kalla «CommandButton1» og ein Listeboks kalla «ListBox1».
Ver konsekvent med små/store bokstavar når du koplar eit kontrollelement til ein objekt-variabel.
Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
Dim oLib as Object ' com.sun.star.script.XLibraryContainer
Dim oLibDialog as Object
Dim oRuntimeDialog as Object
If IsMissing(oLibContainer) Then
oLibContainer = DialogLibraries
End If
oLibContainer.LoadLibrary(LibName)
oLib = oLibContainer.GetByName(Libname)
oLibDialog = oLib.GetByName(DialogName)
oRuntimeDialog = CreateUnoDialog(oLibDialog)
LoadDialog() = oRuntimeDialog
End Function
LoadDialog function is stored in Tools.ModuleControls available from Application Macros and Dialogs.
REM global definisjon av variablar
Dim oDialog1 AS Object
Sub StartDialog1
With GlobalScope.BasicLibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
oDialog1 = Tools.ModuleControls.LoadDialog("Standard", "Dialog1")
oDialog1.Execute()
End Sub
Sub Sample1
With GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
oDialog1 = Tools.LoadDialog("Standard", "Dialog1")
REM hent dialogmodell
oDialog1Model = oDialog1.Model
REM vis tekst for Label1
oLabel1 = oDialog1.GetControl("Label1")
MsgBox oLabel1.Text
REM set ny tekst for kontroll Label1
oLabel1.Text = "New Files"
REM vis modelleigenskapane for Avkryssingsboks1
oCheckBox1Model = oDialog1Model.CheckBox1
MsgBox oCheckBox1Model.Dbg_Properties
REM set ny tilstand for Avkryssingsboks1 til kontrollmodell
oCheckBox1Model.State = 1
REM vis modelleigenskapane for Kommandoknapp1
oCMD1Model = oDialog1Model.CommandButton1
MsgBox oCMD1Model.Dbg_Properties
REM vis modelleigenskapane for Kommandoknapp1
oCMD1 = oDialog1.GetControl("CommandButton1")
MsgBox oCMD1.Dbg_Properties
REM opna dialogvindauget
oDialog1.Execute()
End Sub
Sub AddEntry
With GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
oDialog1 = ModuleControls.LoadDialog("Standard", "Dialog1")
REM legg til eit nytt innslag i listeboksen
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
Dim iCount as integer
iCount = oListbox.ItemCount
oListbox.additem("New Item" & iCount,0)
End Sub
Sub RemoveEntry
With GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
oDialog1 = Tools.ModuleControls.LoadDialogLoadDialog("Standard", "Dialog1")
REM Fjern det første innslaget frå ein listeboks
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
oListbox.removeitems(0,1)
End Sub