Programming Examples for Controls in the Dialog Editor

ឧទាហរណ៍​ដូច​ខាង​ក្រោម​គឺ​សម្រាប់ ប្រអប់ ថ្មី​មួយ​ ហៅ​ថា "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 global definition of 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

អាន ឬ​កែសម្រួល​លក្ខណសម្បត្តិ​នៃ​វត្ថុ​បញ្ជា​ក្នុង​កម្មវិធី


Sub Sample1
    With GlobalScope.Basiclibraries
       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    oDialog1 = Tools.LoadDialog("Standard", "Dialog1")
    REM get dialog model
    oDialog1Model = oDialog1.Model
    REM display text of 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("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 យកធាតុ​ទី​មួយចេញពី ListBox
    oDialog1Model = oDialog1.Model
    oListBox = oDialog1.GetControl("ListBox1")
    oListbox.removeitems(0,1)
End Sub

Please support us!