Dialogs can't see mdichild window controls

I

ian807

I have a legacy vb.net mdi word processor application which I'm
modifying.

I've created many new dialogs. In vb6, I could reference controls on
the child form with code like this:

Dim text as string
temp = frmMDIParent.ActiveForm.TXTextControl1.text

in vb6, this worked from any button on any dialog in the project. In
vb 2005, it returns nothing. How do I get the dialogs to talk to the
frmMDIChild window controls?

Thanks in advance for any help,
Ian
 
C

Chris Dunaway

I have a legacy vb.net mdi word processor application which I'm
modifying.

I've created many new dialogs. In vb6, I could reference controls on
the child form with code like this:

Dim text as string
temp = frmMDIParent.ActiveForm.TXTextControl1.text

in vb6, this worked from any button on any dialog in the project. In
vb 2005, it returns nothing. How do I get the dialogs to talk to the
frmMDIChild window controls?

Thanks in advance for any help,
Ian

The dialog can access the controls of the form, but you must pass the
instance of the form (or control) to the dialog in the constructor.

'Something like this
Dim myDialog As New Dialog(frmMDIChild)

And the inside the dialog, you would have a property or private
variable to hold the form reference. Then you can access the controls
collection of the form.


Another, perhaps better, way is to add a property to the dialog and
then after the dialog closes, you update the MDIChild form:

'In the MDI child form
Dim myDialog As New Dialog() 'nothing passed to the dialog
myDialog.ShowDialog()

Me.TextBox1.Text = myDialog.SomeStringProperty

myDialog.Dispose() 'Remember to Dispose of your dialog forms when
finished with them.

Hope this gives you some ideas.

Chris
 

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