二、系統(tǒng)設(shè)計方法
(一)界面設(shè)計
1.創(chuàng)建和設(shè)計MDI窗體
打開VB6.0,選擇“新建”菜單下的“標(biāo)準(zhǔn)EXE”,然后單擊“打開”按鈕,新建一個標(biāo)準(zhǔn)EXE程序。見圖3-9。
圖3-9 新建工程圖3-10 工程屬性
選擇“工程”菜單中的“添加MDI窗體”命令,添加一個MDI窗體。然后選擇“工程”菜單中的“屬性”命令,彈出如圖3-10所示“工程屬性”對話框,在“啟動對象”的下拉表中選擇剛才創(chuàng)建的MDI窗體為啟動對象,設(shè)置完畢后單擊“確定”按鈕,退出屬性設(shè)置。利用“工具”菜單下的“菜單編輯器”命令編輯如圖3-2所示的菜單,并且利用ToolBar控件為MDI窗體添加工具欄,利用StatusBar控件添加狀態(tài)欄,具體設(shè)計方法可以參考VB程序設(shè)計方面的書籍,此處不再贅述。
2.創(chuàng)建和設(shè)計MDI子窗體
首先創(chuàng)建一個新的普通窗體,然后將它的MDIChild屬性設(shè)置為True,取名為frmDocument,用來存取APT源程序、CL文件、NC程序等。在這個窗體上添加一個RichTextBox控件,用以顯示文檔。另外,再創(chuàng)建一個MDI子窗體,用來顯示圖形,取名為frmDisply。在這個窗體上添加一個Picture控件,用以顯示圖形。
為了使frmDocument子窗體同時存取不同的文檔,在主窗體中添加如下代碼:
Private Sub LoadNewDoc()
Static lDocumentCount As integer
Dim frmD As frmDocument
lDocumentCount = lDocumentCount + 1
Set frmD = New frmDocument
frmD.Caption = "Document " & lDocumentCount
frmD.Show
End Sub
這樣,在存取不同的文檔時,就可以首先調(diào)用LoadNewDoc函數(shù),生成一個子窗體,然后在這個子窗體中存取需要的文檔。
3.部分菜單設(shè)計
文件菜單的子菜單主要包括:新建、打開、關(guān)閉、保存、另存為、全部保存、打印、退出等,用來對文檔進(jìn)行操作。下面詳細(xì)介紹一下新建、打開、保存、打印和退出菜單的代碼設(shè)計。
(1) 新建子菜單的代碼設(shè)計:
Private Sub mnuFileNew_Click()
LoadNewDoc
End Sub
(2) 打開子菜單的代碼設(shè)計:
Public N0 As Integer,WI As Integer, CL(200,7) As Single,
Public BS(200) As String, UnSaveChange As String
Private Sub mnuFileOpen_Click()
On Error Resume Next
LoadNewDoc
With dlgCommonDialog
.DialogTitle = "打開"
.CancelError = False
.Filter = "所有文件 (*.*)|*.*"
.ShowOpen
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
ActiveForm.rtfText.LoadFile sFile
If Right$(sFile, 3) = ".CL" Then‘打開CL文件
N0 = 0
Open sFile For Input As #1
Do While Not EOF(1)
N0 = N0 + 1
Input #1, CL(N0, 1),CL(N0, 2),CL(N0, 3),CL(N0, 4),CL(N0, 5),CL(N0, 6),CL(N0, 7)
Loop
Close #1
Else
WI = 1
Open sFile For Input As #1‘打開APT源程序
Do While Not EOF(1)
Line Input #1, BS(WI)
WI = WI + 1
Loop
Close #1
End If
ActiveForm.Caption = sFile
UnSaveChange = False
End Sub
(3)保存子菜單的代碼設(shè)計:
Private Sub mnuFileSave_Click()
If Left$(ActiveForm.Caption, 8) = "Document" Then
With dlgCommonDialog
.DialogTitle = "保存"
.CancelError = False
.Filter = "所有文件 (*.*)|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
ActiveForm.rtfText.SaveFile sFile, rtfText
Else
sFile = ActiveForm.Caption
ActiveForm.rtfText.SaveFile sFile, rtfText
End If
UnSaveChange = False
End Sub
(4)打印子菜單的代碼設(shè)計:
Private Sub mnuFilePrint_Click()
On Error Resume Next
If ActiveForm Is Nothing Then Exit Sub
With dlgCommonDialog
.DialogTitle = "Print"
.CancelError = True
.Flags = cdlPDReturnDC + cdlPDNoPageNums
If ActiveForm.rtfText.SelLength = 0 Then
.Flags = .Flags + cdlPDAllPages
Else
.Flags = .Flags + cdlPDSelection
End If
.ShowPrinter
End With
If Err <> MSComDlg.cdlCancel Then
ActiveForm.rtfText.SelPrint .hDC
End If
End Sub
(5)退出子菜單的代碼設(shè)計:
Private Sub mnuFileExit_Click()
Unload Me
End Sub
編輯菜單的子菜單包括:撤銷、剪切、復(fù)制、粘貼等,具體代碼可以參考有關(guān)書籍,在此不再敘述。
視圖菜單主要是對工具欄和狀態(tài)欄的操作,具體代碼不再敘述。
窗口菜單主要包括層疊、縱向平鋪、橫向平鋪、排列圖標(biāo)等,其主要功能是對子窗體進(jìn)行各種操作,具體代碼可以參考有關(guān)書籍,在此不再敘述。
業(yè)務(wù)咨詢:932174181 媒體合作:2279387437 24小時服務(wù)熱線:15136468001 盤古機(jī)械網(wǎng) - 全面、科學(xué)的機(jī)械行業(yè)免費(fèi)發(fā)布信息網(wǎng)站 Copyright 2017 PGJXO.COM 豫ICP備12019803號