Mẫu thí dụ Lập trình cho Điều khiển trong bộ Sửa Hộp thoại

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

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

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

    BasicLibraries.LoadLibrary("Tools")

    oDialog1 = 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

    BasicLibraries.LoadLibrary("Tools")

    oDialog1 = 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

    BasicLibraries.LoadLibrary("Tools")

    oDialog1 = 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

    BasicLibraries.LoadLibrary("Tools")

    oDialog1 = LoadDialog("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