Child Form setting Parent Form Property

G

Guest

I have a MDI Windows Form application, within it I have three child forms
that allows a user to provide about 5 paragraphs of text. Instead creating a
large multi-line text box on the child form, I created a "Detail" form, which
contains the large textbox, that the three forms can share.

This detail form is reused by all three forms to capture the user text. I
intended to pass the child form name and child form property in the detail
constructor, then at runtime have the form pass the user text back to calling
form.

Unfortunately because the three forms that are calling the shared Detail
form are child forms of the master mdi form, I can't set them as
mdiContainers, so I can't call the mdiParent parent property in the Detail
Form.

Ideally my code would look something like this:

Form that calls Detail Form:

Form that calls Detail Form:
Friend WriteOnly Property Statement() As String
Set(ByVal Value As String)
mStatement = Value
End Set
End Property

Private Sub btnStatement_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnStatement.Click
Dim detail As New detail(me.getType, "Statement")
detail.ShowDialog()
End Sub

The Detail Form code:

Public Sub New(ByVal FormType as Type, ByVal FormPropertyName As String)
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

mFormType = FormType
mFormPropertyName = FormPropertyName
End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click

[mFormType].[mFormPropertyName].txtUserText.Text 'Pseudo Code
' Hard Code would be: AppName.ChildFormName.Statement =
txtUserText.Text

End Sub

Any thoughts on how to accomplish? Please post code samples in VB. Thanks.

Josh.
 
J

Jeffrey Tan[MSFT]

Hi Josh,

Thanks for your post.

Yes, just as you find out, we can not place a MDI child form as another
form's MDI container, this is by design.

Based on my understanding, the cause you want to use Detail form is that
you want to share this form(Textbox function) code across 3 child forms. If
so, I think we may have 2 other ways:
1. Create a usercontrol, which has the same function as Detail form. That
is placing a TextBox on that Usercontrol, and in 3 MDI child forms, we can
dynamically construct this Usercontrol and adjust its position correctly to
fit our need.
2. Actually, I think we can just inherit the build-in TextBox and create a
customized large multiline TextBox with the function we need. Then we can
just reuse this customized TextBox in all the 3 MDI child forms.

Does this meet your need? If I misunderstand you, please feel free to tell
me, thanks
========================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

I'm limited on space on the 3 child forms, so I wanted to popup a detail form
to capture the text. Since the form has the same functionality I wanted to
reuse the form. Thanks.

Josh.
 
J

Jeffrey Tan[MSFT]

Hi Josh,

Thanks for your feedback.

Sorry, but I do not think I understand your meaning. I can not see why in
your scenario we must use a detail form. Why we can not use an inherited
form or a UserControl?

Hope you can clarify your concern to me. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Here is the big picture:

* One Master MDI Parent Form
* Three child forms that have limited space on the form
* A separate shared X form that can be used by the child forms to obtain
text details from the user.

How do implement X form so that I can refer back to the calling form
dynamically, opposed to hard-coding each form name and property in the X
from. I'm open suggestion on which apporach to take. Thanks.

Josh.
 
J

Jeffrey Tan[MSFT]

Hi Josh,

Thanks for your feedback.

Is your concern on "How do implement X form so that I can refer back to the
calling form dynamically"? If so, I think we can create a constructor for
form X with one parameter of type Form(In the constructor, we can store the
parameter in a class field). Then whenever we create our the form X, we can
pass the calling form's reference as the constructor parameter. So we can
get the calling form reference with the class field.

Hope this helps.
=======================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Yes. I tried the ByRef with the constuctor but I couldn't get that to work.
In addition to passing the form name, I would like to pass the property name
that needs to be set and a default value for the textbox.

The call from the child would look something like this:

Dim detail As New detail(me.getType, "Statement", textVal)
detail.ShowDialog()

Where the first parameter is the form name, the second is the property name,
and the third is any text to populate the form.

Thanks.

Josh.
 
J

Jeffrey Tan[MSFT]

Hi Josh,

Yes, you should pass the information you needed to the form's contructor.

If you still have any concern, please feel free to tell me, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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