Exemples de programmation des contrôles dans l'éditeur de boîte de dialogue

Les exemples suivants se réfèrent à une nouvelle boîte de dialogue appelée "Dialog1". Utilisez les outils de la barre de contrôles dans l'éditeur de boîte de dialogue pour créer la boîte de dialogue et les contrôles suivants : une case à cocher appelée "CheckBox1", un champ d'étiquettes appelé "Label1", un bouton appelé "CommandButton1", et une zone de Liste appelée "ListBox1".

Icône Avertissement

Respectez la casse lorsque vous joignez un contrôle à une variable d'objet.


Fonctions globales pour le chargement des boîtes de dialogue


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 La fonction est stockée dans Tools.ModuleControls disponible à partir de LibreOffice Macros et boîtes de dialogue.

Affichage d'une boîte de dialogue


REM définition globale de variables
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

Lecture ou édition des propriétés des contrôles dans le programme


Sub Sample1
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = Tools.LoadDialog("Standard", "Dialog1")
    REM Obtenir un modèle de boîte de dialogue
    oDialog1Model = oDialog1.Model
    REM Afficher le texte de Label1
    oLabel1 = oDialog1.GetControl("Label1")
    MsgBox oLabel1.Text
    REM Définir un nouveau texte pour le contrôle Label1
    oLabel1.Text = "Nouveaux fichiers"
    REM Afficher les propriétés du modèle pour le contrôle CheckBox1
    oCheckBox1Model = oDialog1Model.CheckBox1
    MsgBox oCheckBox1Model.Dbg_Properties
    REM Définir un nouveau statut pour CheckBox1 pour le modèle de contrôle
    oCheckBox1Model.State = 1
    REM Afficher les propriétés du modèle pour le contrôle CommandButton1
    oCMD1Model = oDialog1Model.CommandButton1
    MsgBox oCMD1Model.Dbg_Properties
    REM Afficher les propriétés du contrôle CommandButton1
    oCMD1 = oDialog1.GetControl("CommandButton1")
    MsgBox oCMD1.Dbg_Properties
    REM Exécuter la boîte de dialogue
    oDialog1.Execute()
End Sub

Ajout d'une entrée à ListBox


Sub AddEntry
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = ModuleControls.LoadDialog("Standard", "Dialog1")
    REM Ajouter une nouvelle entrée au contrôle ListBox
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    Dim iCount as integer
    iCount = oListbox.ItemCount
    oListbox.additem("Nouvel élément" & iCount,0)
End Sub

Suppression d'une entrée du contrôle ListBox


Sub RemoveEntry
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = Tools.ModuleControls.LoadDialogLoadDialog("Standard", "Dialog1")
    REM Supprimer la première entrée du contrôle ListBox
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    oListbox.removeitems(0,1)
End Sub

Aidez-nous !