Ấn kép chuột vào tên frmDocument trong cửa sổ Project để hiển thị nó rồi hiệu chỉnh lại theo mẫu đề nghị Đây là form con của chương trình MDI, nó miêu tả 1 cửa sổ con được tạo ra

Một phần của tài liệu bài thực hành tin học đại cương (Trang 53 - 59)

theo mẫu đề nghị. Đây là form con của chương trình MDI, nó miêu tả 1 cửa sổ con được tạo ra mỗi lần ta thực hiện chức năng New Window. Lưu ý nó chứa menu theo đặc tả ở phần mục đích yêu cầu và 2 control : Timer để định thời và commonDialog để hiển thị các cửa sổ thiết lập thông số máy in. txtSoTugiacChay txtSoLuuAnh txtMaxStep txtTocDo cmdOk

16. Tạo các thủ tục xử lý biến cố cho các option của menu rồi viết code cho chúng như sau :'============================================ '============================================

' Code của các thủ tục xử lý sự kiện trong frmDocument '============================================ Option Explicit

Private inforec As FormInfo 'record chứa thông tin hiển thị của frmDocument Private frmInitAttr As New frmInit ' form thiết lập thông số của frmDocument

' Thủ tục xử lý sự kiện Load form Private Sub Form_Load()

StepTimer.Enabled = False ' cấm timer làm việc Me.BackColor = QBColor(0) ' nền đen

ScaleMode = vbPixels ' đơn vị tính kích thước là pixel mnuViewToolbar.Checked = False ' tắt Toolbar

fMainForm.tbToolBar.Visible = mnuViewToolbar.Checked mnuViewStatusBar.Checked = True ' hiển thị Status bar

fMainForm.sbStatusBar.Visible = mnuViewStatusBar.Checked Form_Resize

End Sub

' Thủ tục xử lý sự kiện vẽ lại form Private Sub Form_Paint()

Set inforec.objFormRef = Me Cls

End Sub

' Thủ tục xử lý sự kiện thay đổi kích thước form Private Sub Form_Resize()

inforec.Xmax = Me.ScaleWidth inforec.Ymax = Me.ScaleHeight End Sub

' Thủ tục xử lý sự kiện chọn option "Edit.Setup Attributes..." Private Sub mnuEditAttr_Click()

StepTimer.Enabled = False ' cấm timer hoạt động

frmInitAttr.txtSoLuuAnh = CStr(inforec.intSoLuuAnh) ' dùng lại giá trị hiện hành frmInitAttr.txtSoTugiac = CStr(inforec.intSoTugiac)

frmInitAttr.txtMaxStep = CStr(inforec.intMaxStep) frmInitAttr.txtTocdo = CStr(inforec.intTocdo)

frmInitAttr.Show vbModal ' hiển thị form setup If Val(frmInitAttr.txtSoLuuAnh) > 0 Then ' xử lý số lưu ảnh inforec.intSoLuuAnh = Val(frmInitAttr.txtSoLuuAnh)

Else

inforec.intSoLuuAnh = SOLUUANHMAX End If

If Val(frmInitAttr.txtMaxStep) > 1 Then ' xử lý số bước chạy max inforec.intMaxStep = Val(frmInitAttr.txtMaxStep)

Else

inforec.intMaxStep = MAXSTEP End If

If Val(frmInitAttr.txtSoTugiac) > 0 Then ' xử lý số tứ giác chạy inforec.intSoTugiac = Val(frmInitAttr.txtSoTugiac)

Else

inforec.intSoTugiac = SOTUGIACMAX End If

If Val(frmInitAttr.txtTocdo) > 0 Then ' xử lý tốc độ chạy inforec.intTocdo = Val(frmInitAttr.txtTocdo)

Else

inforec.intTocdo = TOCDOMAX End If (adsbygoogle = window.adsbygoogle || []).push({});

ReDim inforec.DsTugiac(inforec.intSoTugiac) ' tạo số từ giác chạy Call KhoidongCacTugiac(inforec) ' khởi động chúng StepTimer.Interval = inforec.intTocdo ' cho timer chạy để hiển thị End Sub

' Thủ tục tạo 1 cửa sổ con mới Private Sub LoadNewDoc() Dim frmD As frmDocument

lDocumentCount = lDocumentCount + 1 ' biến public này được khai báo ở Module1 Set frmD = New frmDocument

frmD.Caption = "Cua so tu giac thu " & lDocumentCount frmD.Show

End Sub

' Thủ tục xử lý sự kiện chọn option "Edit.Start" Private Sub mnuEditStart_Click()

StepTimer.Enabled = True End Sub

' Thủ tục xử lý sự kiện chọn option "File.Exit" Private Sub mnuFileExit_Click()

Unload fMainForm End Sub

' Thủ tục xử lý sự kiện chọn option "File.Page Setup" Private Sub mnuFilePageSetup_Click()

On Error Resume Next With dlgCommonDialog .DialogTitle = "Page Setup" .CancelError = True

.ShowPrinter End With End Sub

Private Sub mnuFilePrint_Click() PrintForm

End Sub

' Thủ tục xử lý sự kiện chọn option "View.Status Bar" Private Sub mnuViewStatusBar_Click()

mnuViewStatusBar.Checked = Not mnuViewStatusBar.Checked fMainForm.sbStatusBar.Visible = mnuViewStatusBar.Checked End Sub

' Thủ tục xử lý sự kiện chọn option "View.ToolBar" Private Sub mnuViewToolbar_Click()

mnuViewToolbar.Checked = Not mnuViewToolbar.Checked fMainForm.tbToolBar.Visible = mnuViewToolbar.Checked End Sub

' Thủ tục xử lý sự kiện chọn option "Window.Arrange" Private Sub mnuWindowArrange_Click()

fMainForm.Arrange vbArrangeIcons End Sub

' Thủ tục xử lý sự kiện chọn option "Window.Cascade" Private Sub mnuWindowCascade_Click()

fMainForm.Arrange vbCascade End Sub

Private Sub mnuWindowNew_Click() LoadNewDoc

End Sub

' Thủ tục xử lý sự kiện chọn option "Window.Tile Horizontal" Private Sub mnuWindowTileHori_Click()

fMainForm.Arrange vbTileHorizontal End Sub

' Thủ tục xử lý sự kiện chọn option "Window.Tile Vertical" Private Sub mnuWindowTileVerti_Click()

fMainForm.Arrange vbTileVertical End Sub

' Thủ tục xử lý sự kiện timer out" Private Sub StepTimer_Timer() Call VeCacTugiac(inforec) End Sub

' Thủ tục xử lý sự kiện Help.About" Private Sub mnuHelpAbout_Click() frmAbout.Show vbModal (adsbygoogle = window.adsbygoogle || []).push({});

End Sub

Một phần của tài liệu bài thực hành tin học đại cương (Trang 53 - 59)