I have an MDI parent form that may open a child form called “Order”. Order forms have a button that allows the user to print the order. The Order form has a print size variable defined at the beginning:
Public Class Order
Public psize As String
Private Sub button_order_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles process_order.Click
' Code to handle the order and then print, etc
Now the parent form has a psize variable as well, which is set to a default of “A4”.
Only when someone clicks on one of the menu items on the Parent window’s menu strip will this happen:
psize = "A6"
By default, whenever the parent window opens up a new Order form, I need it to set the child form’s psize variable to its own psize value. Something like this:
Dim f As Form
f = New Order
f.MdiParent = Me
f.psize = Me.psize ' BUT THIS LINE DOESN'T WORK
f.Show()
I get the error that f.psize is not a member of the form.
I know that passing variables to and from the MDI parent and child is quite common but despite trying out a few options I saw here, it doesn’t seem to be working. Is this the wrong approach?
The reason the property is not available is because you are using the wrong type for the variable. The base
Formtype does not define that property. Instead, your derivedOrdertype does. You could do something like this:UPDATE
As you have said in comments below, what you really need to do is to be able to share a dynamic setting between all your forms so that you can change the setting at any time and have it affect all your forms that have already been displayed. The best way to do that, would be to create a new class that stores all your shared settings, for instance:
As you can see, by doing so, you can easily centralize all your default settings in your settings class, which is an added benefit. Then, you need to change the public property in your
Orderform to the newSettingstype, for instance:Then, you need to create your shared settings object in your MDI Parent form, and then pass it it to each of your
Orderforms as they are created:Then, since the parent form and all the child
Orderforms share the sameSettingsobject, and change made to thatSettingsobject will be seen immediately by all the forms.