Code for the default menu items

[Top]  [Chapter]  [Previous]  [Next]

OpenFile:

 

       Dim ChildForm As New WordsChildForm1

          ChildForm.MdiParent = Me

          ChildForm.Text = FileName

          ChildForm.Show()

          Dim memo As WPDynamic.IWPMemo

          memo = ChildForm.WpdllInt1.Memo

          If (memo Is Nothing) Or _

            Not memo.LoadFromFile(FileName, False, "AUTO") Then

              MessageBox.Show("Cannot load " + FileName)

              ChildForm.Dispose()

          End If

 

SaveAs:

 

       If Not WpdllInt1 Is Nothing Then

              Dim memo As WPDynamic.IWPMemo

              memo = ChildForm.WpdllInt1.Memo

              If Not memo.SaveToFile(FileName, False, "AUTO") Then

                  MessageBox.Show("Cannot write " + FileName)

              End If

          End If

 

Cut:

 

      If Not WpdllInt1 Is Nothing Then

          Dim memo As WPDynamic.IWPMemo

          memo = WpdllInt1.Memo

          memo.CutToClipboard()

      End If

 

Copy:        memo.CopyToClipboard()

 

Paste:        memo.PasteFromClipboard()

 

Undo:        memo.TextCursor.Undo()

 

Redo:        memo.TextCursor.Redo()

 

SelectAll:        memo.TextCursor.SelectAll()

 

PrintPreview:        memo.ShowDialog(WPDynamic.DialogID.Preview, "", "")

 

Print:        memo.ShowDialog(WPDynamic.DialogID.Preview, "", "")

 

 

Still missing is some code to update the enabled state of the standard buttons and menu items. Since the UpdateGUI event gets a bitfield parameter with the required states we only need a unitilty methiod which processes this bits. We use a public sub procedure in the MDI parent and call it from the UpdateGUI event on the child form.

 

In the MDI Parent:

 

  Public Sub UpdateStandardActionState(ByVal StateFlags As Integer)

      ' Modified Flag

      SaveToolStripButton.Enabled = ((StateFlags And 1) <> 0)

      SaveAsToolStripMenuItem.Enabled = ((StateFlags And 1) <> 0)

      ' Inserting mode (update item 3 in status bar)

      If ((StateFlags And 2) <> 0) Then

          StatusStrip.Items(2).Text = "INS"

      Else

          StatusStrip.Items(2).Text = ""

      End If

      ' UNDO State

      UndoToolStripMenuItem.Enabled = ((StateFlags And 4) <> 0)

      ' REDO State

      RedoToolStripMenuItem.Enabled = ((StateFlags And 8) <> 0)

      ' Copy, Cut - if Text is selected

      CopyToolStripMenuItem.Enabled = ((StateFlags And 16) <> 0)

      CutToolStripMenuItem.Enabled = ((StateFlags And 16) <> 0)

  End Sub

 

In the MDI Child:

 

  Private Sub WpdllInt1_OnUpdateGUI(....) Handles WpdllInt1.OnUpdateGUI

      WordsMDIParent1.ReadCurrentAttributes(WpdllInt1)

      WordsMDIParent1.UpdateStandardActionState(StateFlags)

      WordsMDIParent1.StatusStrip.Items(0).Text = Convert.ToString(PageNr) _

         + "/" + Convert.ToString(PageCount)

      WordsMDIParent1.StatusStrip.Items(1).Text = Convert.ToString(LineNr)

  End Sub


[codeforthedefaultmenuitem.htm]    Copyright © 2007 by WPCubed GmbH