LibreOffice 24.8 Help
الأمثلة التالية هي لمربع حوار جديد يُدعى "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 Application 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 = "ملفات جديدة"
    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 يضيف إدخال جديد إلى مربع القائمة
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    Dim iCount as integer
    iCount = oListbox.ItemCount
    oListbox.additem("عنصر جديد" & 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 إزالة الإدخال الأول من مربع القائمة
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    oListbox.removeitems(0,1)
End Sub