Collabora Office 21.06 帮助
以下示例针对的是一个名为 "Dialog1" 的新对话框。使用对话框编辑器中的「工具箱」栏上的工具可以创建对话框并添加下列控件: 名为 "CheckBox1" 的「复选框、名为 "Label1" 的「标签字段」、名为 "CommandButton1" 的按钮」以及名为 "ListBox1" 的「列表框」。
在将控件附加到对象变量时,请使字母大小写保持一致。
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 Collabora Office Macros and Dialogs.
REM 全局变量定义
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 获取对话框模型
oDialog1Model = oDialog1.Model
REM 显示 Label1 的文字
oLabel1 = oDialog1.GetControl("Label1")
MsgBox oLabel1.Text
REM 设置控件 Label1 的新文字
oLabel1.Text = "New Files"
REM 显示控件 CheckBox1 的模型属性
oCheckBox1Model = oDialog1Model.CheckBox1
MsgBox oCheckBox1Model.Dbg_Properties
REM 为 CheckBox1 的控件模型设置新状态
oCheckBox1Model.State = 1
REM 显示控件 CommandButton1 的模型属性
oCMD1Model = oDialog1Model.CommandButton1
MsgBox oCMD1Model.Dbg_Properties
REM 显示控制 CommandButton1 的属性
oCMD1 = oDialog1.GetControl("CommandButton1")
MsgBox oCMD1.Dbg_Properties
REM 执行对话框
oDialog1.Execute()
End Sub
Sub AddEntry
With GlobalScope.Basiclibraries
If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
End With
oDialog1 = ModuleControls.LoadDialog("Standard", "Dialog1")
REM 向 ListBox 中添加新条目
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 删除 ListBox 中的第一个条目
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
oListbox.removeitems(0,1)
End Sub