Programming Examples for Controls in the Dialog Editor

Những mẫu thị dụ theo đây thuộc về một hộp thoại có tên « Hộp thoại 1 ». Hãy dùng các công cụ trên thanh Hộp công cụ trong bộ sửa hộp thoại, để tạo hộp thoại và thêm những điều khiển này: một Hộp chọn tên « Hộp chọn 1 », một Trường nhãn tên « Nhãn 1 », một Nút tên « Nút lệnh 1 », và một Hộp liệt kê tên « Hộp liệt kê 1 ».

Biểu tượng Cảnh báo

Khi gắn điều khiển với biến đối tượng, dùng chữ hoa/thường một cách thống nhất.


Hàm Toàn cục để Nạp Hộp thoại


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 LibreOffice Macros and Dialogs.

Hiển thị hộp thoại


rem lời xác định toàn cục các biến
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

Đọc hay Sửa Các thuộc tính của Điều khiển trong Chương trình


Sub Sample1
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = Tools.LoadDialog("Standard", "Dialog1")
    REM lấy mô hình hộp thoại
    oDialog1Model = oDialog1.Model
    REM hiển thị văn bản của nhãn Label1
    oLabel1 = oDialog1.GetControl("Label1")
    MsgBox oLabel1.Text
    REM đặt văn bản mới cho điều khiển Label1
    oLabel1.Text = "New Files"
    REM hiển thị các thuộc tính mô hình cho điều khiển hộp chọn CheckBox1
    oCheckBox1Model = oDialog1Model.CheckBox1
    MsgBox oCheckBox1Model.Dbg_Properties
    REM đặt tình trạng mới cho CheckBox1 cho mô hình của điều khiển
    oCheckBox1Model.State = 1
    REM hiển thị các thuộc tính mô hình cho điều khiển nút CommandButton1
    oCMD1Model = oDialog1Model.CommandButton1
    MsgBox oCMD1Model.Dbg_Properties
    REM hiển thị các thuộc tính của điều khiển nút CommandButton1
    oCMD1 = oDialog1.GetControl("CommandButton1")
    MsgBox oCMD1.Dbg_Properties
    REM thực hiện hộp thoại
    oDialog1.Execute()
End Sub

Thêm Mục vào Hộp Liệt kê


Sub AddEntry
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = ModuleControls.LoadDialog("Standard", "Dialog1")
    REM thêm một mục mới vào Hộp Liệt kê
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    Dim iCount as integer
    iCount = oListbox.ItemCount
    oListbox.additem("New Item" & iCount,0)
End Sub

Gỡ bỏ Mục khỏi Hộp Liệt kê


Sub RemoveEntry
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = Tools.ModuleControls.LoadDialogLoadDialog("Standard", "Dialog1")
    REM gỡ bỏ mục nhập thứ nhất khỏi Hộp Liệt kê
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    oListbox.removeitems(0,1)
End Sub

Please support us!