Programming Examples for Controls in the Dialog Editor

下記の例は、「Dialog1」と名付けた新規ダイアログを制御するためのものです。 このダイアログを作成する際には、ダイアログエディター上で コントロール 可動ツールバーを表示させ、該当するツールを用いて、次のコントロールを配置しておきます: 「CheckBox1」という名前の チェックボックス 1 個、「Label1」という名前の ラベルフィールド (図表番号ボックス) 1 個、「CommandButton1」という名前の ボタン 1 個、「ListBox1」という名前の リストボックス 1 個。

警告マーク

オブジェクト変数にコントロールを割り当てる際には、上記の名前の大文字と小文字を一致させる必要があります。


ダイアログの読み込み用の大域関数


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 = "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 リストボックスへの項目追加
    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 リストボックスの 1 番目の項目の削除
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    oListbox.removeitems(0,1)
End Sub

ご支援をお願いします!