Presentation is loading. Please wait.

Presentation is loading. Please wait.

MDI with Menu Please use speaker notes for additional information!

Similar presentations


Presentation on theme: "MDI with Menu Please use speaker notes for additional information!"— Presentation transcript:

1 MDI with Menu Please use speaker notes for additional information!

2 MDI

3

4

5

6 This is the parent. This is the child.

7 MDI I am selecting Project/Project1Properties - if I had changed the name of the Project at this point, I would see that name here.

8 MDI

9

10

11

12

13

14 Note the appearance of the menu with the separator.

15 MDI

16

17 Code This gives a name to the type that was described in the bas module.

18 Code - File/New Private Sub mnuFileNew_Click() AddCustomer End Sub Private Function AddCustomer() As frmMDIChild1 Set AddCustomer = New frmMDIChild1 AddCustomer.Show vbModeless End Function This is used to create a function - the standard code it creates is shown. This is the code after I have changed it. When the File/New option is clicked then I coded mnuFileNew to do one thing - execute the function AddCustomer. HOW I CREATED THE FUNCTION:

19 Private Sub mnuFileOpen_Click() fileOut = App.Path If Right(fileOut, 1) <> "\" Then fileOut = fileOut & "\" End If fileOut = fileOut & "MDICustomer" Open fileOut For Random As #1 Len = Len(custRec) mnuFileOpen.Enabled = False End Sub Code - File/Open, MDIForm_Load The file out is being opened as a random file which calls for providing the length of the record. Private Sub MDIForm_Load() AddCustomer End Sub Note that when the form is loaded, the AddCustomer function shown on the previous slide is executed. BEFORE AFTER Setting the enabled property of mnuFileOpen to false at execution time means that it changes in the availability of this option.

20 Private Sub mnuFileClose_Click() Unload frmMDIParent.ActiveForm End Sub Code - File/Close, File/Exit Private Sub mnuFileExit_Click() Dim ct As Integer For ct = 1 To Forms.Count - 1 Unload frmMDIParent.ActiveForm Next ct Unload frmMDIParent End End Sub This unloads the current active form which in the case of an MDI form means the current active child.

21 Code - File/Exit

22 Private Sub mnuFileSave_Click() custRec.fldCustNo = frmMDIParent.ActiveForm.txtCustomer.Text custRec.fldProblem = frmMDIParent.ActiveForm.txtProblem.Text custRec.fldComments = frmMDIParent.ActiveForm.txtComments.Text recordNum = recordNum + 1 Put #1, recordNum, custRec End Sub Code - File/Save This refers to the active child.

23 Private Sub mnuEditCopy_Click() CopyClipboard End Sub Code - Edit/Copy The copy puts information on the clipboard using the routine CopyClipboard. Private Sub CopyClipboard() Clipboard.SetText frmMDIParent.ActiveForm.ActiveControl.SelText End Sub The SetText method has the following syntax: object.SetText data, format In this example, I am providing the data to the clipboard that was selected on the active child form.

24 Private Sub RemoveSelected() wkText = frmMDIParent.ActiveForm.ActiveControl.Text wkSelStart = frmMDIParent.ActiveForm.ActiveControl.SelStart wkSelLength = frmMDIParent.ActiveForm.ActiveControl.SelLength frmMDIParent.ActiveForm.ActiveControl = Left(wkText, wkSelStart) & _ Right(wkText, Len(wkText) - (wkSelStart + wkSelLength)) frmMDIParent.ActiveForm.ActiveControl.SelStart = wkSelStart End Sub Private Sub mnuEditCut_Click() CopyClipboard RemoveSelected End Sub The cut not only puts information on the clipboard, it also executes the routine to remove the selected data (RemoveSelected). Code - Edit/Cut Let’s say the text entered into the active control (the field that has the cursor pointing to it), is THE DOG ATE MY HOMEWORK. The Len(wkText) is 23. Let’s say that I selected DOG ATE. The wkSelStart is therefore 4 and the wkSelLength is 8. Now I go in on the left of the text to wkSelStart which means I go into the 4th character (starts with 0) which is D, then I go to the Right of the data to the point that is 23 - (4 + 8) which means 23 - 12which means 11 that points to the M of MY. This lays out the data that should be eliminated. I then concatenate the part up to the D with the part start with the M.

25 Private Sub mnuEditPaste_Click() If frmMDIParent.ActiveForm.ActiveControl.SelLength > 0 Then RemoveSelected End If wkText = frmMDIParent.ActiveForm.ActiveControl wkSelStart = frmMDIParent.ActiveForm.ActiveControl.SelStart wkClipboard = Clipboard.GetText frmMDIParent.ActiveForm.ActiveControl = Left(wkText, wkSelStart) & wkClipboard _ & Right(wkText, Len(wkText) - wkSelStart) frmMDIParent.ActiveForm.ActiveControl.SelStart = wkSelStart End Sub Code - Edit/Paste This IF statement determines if text was highlighted when you said to paste. If it was, you want to remove the highlighted text before pasting. Note: This is how it would work in Word for example. I am moving things into work areas. I am concatenating everything before the cursor, with what is on the clipboard with everything after the cursor. Left(wkText, wkSelStart) is everything before the cursor. wkClipboard is what is on the clipboard Right(wkText, Len(wkText) - wkSelStart) is everything that comes after the cursor - it does this by looking at the length of the text and subtracting the location of the cursor.

26 Option Explicit Dim fileOut As String Dim recordNum As Integer Dim custRec As randomCustomer Dim wkSelLength As Long Dim wkText As String Dim wkClipboard As String Dim wkSelStart As Long Private Function AddCustomer() As frmMDIChild1 Set AddCustomer = New frmMDIChild1 AddCustomer.Show vbModeless End Function Private Sub mnuEditCopy_Click() CopyClipboard End Sub Private Sub mnuEditCut_Click() CopyClipboard RemoveSelected End Sub Private Sub mnuEditPaste_Click() If frmMDIParent.ActiveForm.ActiveControl.SelLength > 0 Then RemoveSelected End If wkText = frmMDIParent.ActiveForm.ActiveControl wkSelStart = frmMDIParent.ActiveForm.ActiveControl.SelStart wkClipboard = Clipboard.GetText frmMDIParent.ActiveForm.ActiveControl = Left(wkText, wkSelStart) & wkClipboard _ & Right(wkText, Len(wkText) - wkSelStart) frmMDIParent.ActiveForm.ActiveControl.SelStart = wkSelStart End Sub

27 Private Sub mnuFileClose_Click() Unload frmMDIParent.ActiveForm End Sub Private Sub mnuFileExit_Click() Dim ct As Integer For ct = 1 To Forms.Count - 1 Unload frmMDIParent.ActiveForm Next ct Unload frmMDIParent End End Sub Private Sub mnuFileNew_Click() AddCustomer End Sub Private Sub mnuFileOpen_Click() fileOut = App.Path If Right(fileOut, 1) <> "\" Then fileOut = fileOut & "\" End If fileOut = fileOut & "MDICustomer" Open fileOut For Random As #1 Len = Len(custRec) mnuFileOpen.Enabled = False End Sub Private Sub mnuFileSave_Click() custRec.fldCustNo = frmMDIParent.ActiveForm.txtCustomer.Text custRec.fldProblem = frmMDIParent.ActiveForm.txtProblem.Text custRec.fldComments = frmMDIParent.ActiveForm.txtComments.Text recordNum = recordNum + 1 Put #1, recordNum, custRec End Sub Private Sub MDIForm_Load() AddCustomer End Sub

28 Private Sub CopyClipboard() Clipboard.SetText frmMDIParent.ActiveForm.ActiveControl.SelText End Sub Private Sub RemoveSelected() wkText = frmMDIParent.ActiveForm.ActiveControl.Text wkSelStart = frmMDIParent.ActiveForm.ActiveControl.SelStart wkSelLength = frmMDIParent.ActiveForm.ActiveControl.SelLength frmMDIParent.ActiveForm.ActiveControl = Left(wkText, wkSelStart) & _ Right(wkText, Len(wkText) - (wkSelStart + wkSelLength)) frmMDIParent.ActiveForm.ActiveControl.SelStart = wkSelStart End Sub


Download ppt "MDI with Menu Please use speaker notes for additional information!"

Similar presentations


Ads by Google