Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

It's my 1st time that I use mdi forms.

 

However, my startup form is named "Form1" and its "IsMdiContainer" property is set to true.

I only have another form named "DocumentForm" which just contains a Microsoft DHTML Editing control.

And I open it from MainForm using:

       Dim Document As DocumentForm = New DocumentForm
       Document.MdiParent = Me
       Document.WindowState = FormWindowState.Maximized
       Document.Show()
       Document.Update()

It seems to be OK, but when I want to get "DocumentForm.DHTMLEdit.IsDirty" property from MainForm, I cannot!

How can I access these from MainForm?

Thanks.

  • Leaders
Posted
The easiest way to do this is to go to the designer of DocumentForm, select your DHTML control, and set its "Modifiers" property to "Friend" or "Public." You also need to keep a reference to your document form, probably using a class-level variable (unless you are using a version of VB that supports default instances and it is enabled).
[sIGPIC]e[/sIGPIC]
Posted

The easiest way to do this is to go to the designer of DocumentForm, select your DHTML control, and set its "Modifiers" property to "Friend" or "Public."

 

>> I set it to Public.

 

 

You also need to keep a reference to your document form, probably using a class-level variable (unless you are using a version of VB that supports default instances and it is enabled).

 

>> I don't understand this section, what should I do exactly? I use VB.NET 2005. Thanks:)

  • Leaders
Posted
[Color=Green]' Option 1 - Only works if there is only one Form2, not very MDI friendly.
[/Color]  [Color=Blue]  Private Sub [/Color]NewDocumentToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]NewDocumentToolStripMenuItem.Click
       Form2.Text = "New Document " + ([Color=Blue]Me[/color].MdiChildren.Length + 1).ToString()
       Form2.MdiParent = [Color=Blue]Me[/Color]
       Form2.WindowState = FormWindowState.Maximized
       Form2.Show()
       Form2.Update()
   [Color=Blue]End Sub[/Color]

   [Color=Blue]Private Sub [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem.Click
       MessageBox.Show(Form2.TextBox1.Text)
 [Color=Blue]  End Sub[/Color]

[Color=Green]' Option 2 - Probably better[/Color]
   [Color=Blue]Dim [/Color]Documents [Color=Blue]As New [/Color]List([Color=Blue]Of [/Color]Form2) [Color=Green]' Depending on your approach, you might not need this.[/Color]

  [Color=Blue] Private Sub [/Color]NewDocumentToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]NewDocumentToolStripMenuItem.Click
       [Color=Blue]Dim [/Color]Document [Color=Blue]As [/Color]Form2 = [Color=Blue]New [/Color]Form2
       Document.Text = "New Document " + ([Color=Blue]Me[/color].MdiChildren.Length + 1).ToString()
       Document.MdiParent = [Color=Blue]Me[/Color]
       Document.WindowState = FormWindowState.Maximized
       Document.Show()
       Form2.Update()

       Documents.Add(Document)
[Color=Blue]    End Sub[/Color]

   [Color=Blue]Private Sub [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem_Click([Color=Blue]ByVal [/Color]sender [Color=Blue]As [/Color]System.Object, [Color=Blue]ByVal [/Color]e [Color=Blue]As [/Color]System.EventArgs) [Color=Blue]Handles [/Color]ShowTextInTheSelectedChildFormToolStripMenuItem.Click
      [Color=Green] ' I don't know how you plan on picking wich document to perform the action

       ' This would perform the action on all documents
[/Color]        [Color=Blue]For Each [/Color]Document [Color=Blue]As [/Color]Form2 [Color=Blue]In [/Color]Documents
           MessageBox.Show(Document.TextBox1.Text)
       [Color=Blue]Next[/Color]


       [Color=Green]' This would perform the action on the currently active document
[/Color]        [Color=Blue]Dim [/Color]SingleDocument [Color=Blue]As [/Color]Form2 = [Color=Blue]TryCast[/Color](Me.ActiveMdiChild, Form2)
       [Color=Blue]If [/Color](Form2 [Color=Blue]IsNot Nothing[/Color]) [Color=Blue]Then[/Color]
           MessageBox.Show(SingleDocument.TextBox1.Text)
       [Color=Blue]End If
   End Sub[/Color]

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...