Search In Site

24 June, 2013

How To Coordinate Data Between MDI Child Forms


Coordinating Data Between MDI Child Forms (Document Views)
Your new word-processor program is almost done just one more refinement to add. You want to allow the user to open multiple views into the same document. A view is just a window into a document, and if a document has multiple views open, the user can scroll around in different parts of the same document at the same time. You ve been able to open the same document in several view windows now but what if the user starts typing into one view? All the other views should also be updated with the new text as well. How do you
keep all the open views of the same document coordinated? 

We ll see how this works now. In this example, the MDI child windows will be based on a form, Form1, in which we ve placed a text box. The user can open as many MDI child windows as they like with the New item in the Window menu. When they type in one MDI child s text box, however, we should mirror any such changes in the other MDI children s text boxes as well. 

Coordinating MDI children. We start by adding a new module to the program with the Project[vbar]Add Module item so that we can set up a global array of forms, Forms, and an array index variable, NumberForms, in that module:

Public Forms(1 To 20) As Form1
Public NumberForms As Integer
Next, we add a Window menu to the MDI form. We also add new forms to that array of forms when the user creates such new forms by adding this code to the MDI form s New item in the Window menu:

Private Sub NewWindow_Click()
NumberForms = NumberForms + 1
Set Forms(NumberForms) = New Form1
Forms(NumberForms).Caption = "Document" & Str(NumberForms)
Forms(NumberForms).Show
End Sub
Now the Forms array holds the MDI children in our program. When the user types text into the text box displayed in an MDI child, we want to update all
the other MDI children as well, making them display the same text. When you type into a text box, a Change event occurs, and we ll add code to that event s handler function to update all the other MDI children:
Private Sub Text1_Change()
End Sub
Here, we store the text in the just-changed text box and, in this simple example, just loop over all MDI children, updating them to match the changed text box:
Private Sub Text1_Change()
Dim Text As String
Text = Text1.Text
For intLoopIndex = 1 To NumberForms
Forms(intLoopIndex).Text1.Text = Text
Next intLoopIndex
End Sub
Now when you change the text in one child, the text in all children is updated. In this way, we can support multiple views into the same document.


0 comments:

Post a Comment

Dear Visitors All The Tricks And Hacks Posted Here Are Only For Knowledge Purpose.Don't Use These for Illegal Operations.

 
Twitter Bird Gadget