대화 상자 편집기의 콘트롤에 대한 프로그래밍 예
다음은 "Dialog1"이라는 새 대화 상자에 대한 예입니다. 대화 상자 편집기의 도구 상자 모음에 있는 도구를 사용하여 대화 상자를 만들고 "CheckBox1"이라는 확인란, "Label1"이라는 레이블 필드, "CommandButton1"이라는 버튼, "ListBox1"이라는 목록 상자 등의 콘트롤을 추가합니다.
콘트롤을 개체 변수에 추가할 때 대문자와 소문자가 정확하게 일치하도록 해야 합니다. |
대화 상자 로드를 위한 전역 함수
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
대화 상자 표시
REM 전역 변수 정의
Dim oDialog1 AS Object
Sub StartDialog1
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
oDialog1.Execute()
End Sub
프로그램에서 콘트롤의 속성 읽기 또는 편집
Sub Sample1
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
REM get dialog model
oDialog1Model = oDialog1.Model
REM display text of Label1
oLabel1 = oDialog1.GetControl("Label1")
MsgBox oLabel1.Text
REM set new text for control Label1
oLabel1.Text = "New Files"
REM display model properties for the control CheckBox1
oCheckBox1Model = oDialog1Model.CheckBox1
MsgBox oCheckBox1Model.Dbg_Properties
REM set new state for CheckBox1 for model of control
oCheckBox1Model.State = 1
REM display model properties for control CommandButton1
oCMD1Model = oDialog1Model.CommandButton1
MsgBox oCMD1Model.Dbg_Properties
REM display properties of control CommandButton1
oCMD1 = oDialog1.GetControl("CommandButton1")
MsgBox oCMD1.Dbg_Properties
REM execute dialog
oDialog1.Execute()
End Sub
ListBox에 항목 추가
Sub AddEntry
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
REM adds a new entry to the ListBox
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
Dim iCount as integer
iCount = oListbox.ItemCount
oListbox.additem("New Item" & iCount,0)
End Sub
ListBox에서 항목 제거
Sub RemoveEntry
BasicLibraries.LoadLibrary("Tools")
oDialog1 = LoadDialog("Standard", "Dialog1")
REM remove the first entry from the ListBox
oDialog1Model = oDialog1.Model
oListBox = oDialog1.GetControl("ListBox1")
oListbox.removeitems(0,1)
End Sub