Accessing a control from on form to another in MDI

G

Gary Townsend

I have seen similar requests to this but not quite what i was looking for i
have an mdi interface and i have 3 child forms 2 are application forms
(meaning they do stuff for the application) and the other is a debug window
with a multiline text field for displaying debug messages within the
application.

What happens is i load the debug form on the mdi parents load event and
minimize it then i load my application forms. What i want to know is how to
be able to write messages to the debug window. I had at one point tried to
create the debug window as a global property of the MDI parent but i haven't
been able to reference the frmDebug property that i made within my child
forms. So now i am looking for other suggestions.
 
G

Guest

Gary,

Create a "global" variable on the MDI form to reference the debug form:

Public debugForm As Form2

In the MDI form's Load event, load the debug form:

debugForm = New Form2

debugForm.MdiParent = Me

debugForm.Show()

On any MDI Child application form, write to the debug form:

Dim f As Form1 = Me.MdiParent

f.debugForm.TextBox2.Text = f.debugForm.TextBox2.Text &
ControlChars.NewLine & "Debug info"

Kerry Moorman
 
G

Gary Townsend

Thanks Kerry right after i sent it i had a brain wave and figured if i
created a public debug window object on the child form i could load the
debug window on the parent form then pass the parent window's debug window
to the child when it loads, i then created a public sub on the debug form
that takes care of my writing to the text box.: Makes more sense if i show
it:

Public Class frmParent
Inherits System.Windows.Forms.Form
Public frmDebug As New Debug

Private Sub frmParent_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
frmDebug.MdiParent = Me
frmDebug.Show()
frmDebug.WindowState = FormWindowState.Minimized
End Sub

Private Sub OpenMap_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MenuOpenMapWindow.Click
Dim MapForm As New frmMain

MapForm.MdiParent = Me
MapForm.Show()
MapForm.DebuggingForm = frmDebug
End Sub

End Class

Public Class frmMain
Inherits System.Windows.Forms.Form
Public DebuggingForm As Debug

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top