Link to home
Start Free TrialLog in
Avatar of Jarrod
JarrodFlag for Australia

asked on

vb.net 2015 mdi and forms, clicking buttons on other forms using code

I have an app im trying to develop where im using an MDI form and have multiple forms showing inside it at once, id like to call the button click event when I do a particular action on another form but keep getting the object is not a member of form. So Im assuming its a private object but I cant find anywhere I can change it to public, can someone point me in the right direction ?
Avatar of ste5an
ste5an
Flag of Germany image

Please rephrase your question. What button? Where is it placed? How are your MDI windows structured (inheritance)?

When MDI is the correct UI structure, then you should look into the command, observer and visitor patterns.
Even using event sourcing pattern may be useful.
If there is a necessary coupling or dependency between your MDI children, then you should also look into the chain of responsibility pattern.

Making a member public for your concrete use-case maybe a cheap and fast way to solve your problem, but it adds technical debt - namely too tight coupling - from the architectural viewpoint.
I agree that calling a button's Click event from another form is not best practices.

But if you really have to, check the Modifiers property of your button.
Avatar of Jarrod

ASKER

I knocked up a  basic example attached, sorry for the poor wording

In essence the main app is designed as a wizard so I have a thin height form down the bottom of the mdi window that has buttons to go forwards, backwards etc through the wizard process and I change the form above it as the user steps through the wizard. That aspect is working fine except for when one of the forms in the upper section has buttons as well for different functions and I need it to progress through, hence me trying to initiate the click on the bottom form where the navigation is meant to occur
example.JPG
A wizard pre se is a state machine. Where a single state is normally represented by a single view.

So each of your forms normally represent a single state. And they only talk to the wizard host (context). Not to each other.

And the result of a wizard is normally a chain of commands, which are executed at the end. This means, as long as you're in the wizard, there are no side effects.

p.s. when it's really a wizard, then using a MDI is irrelevant (or wrong).
I described a couple of methods in this previous EE PAQ: https:/Q_29071252.html#a42387887

-saige-
in an MDI (multi document interface) architecture any of your forms is a so-called view that was associated to a document (class) object and a frame (class) object. the document is meant to hold the data that was displayed in the associated view. the frame is meant to hold menus and navigation controls. frame and view are the presentation part of that architecture and document and application are the application (data) part. in an SDI (single document interface) there is only one document and one frame. anyway,  if a form would need to sync with another form, it either would use the associated document or the parent frame object depending on whether the sync is more a data sync or a navigation sync. if you really have multiple documents (and/or frames) where i have doubts, you would use the application (or mainframe if multiple frames) class for sync. the point is, you never would call between forms but alway call a document or frame function which then does the needed thing by using the correct hierarchy paths.

SDI:  
                    app
                        |
            (doc - frame)
            /          |         \
       form1  form2  form3
 
MDI :
                          (app - main frame)
                /                        |                          \
    (doc1 - frame1)  (doc2 - frame2) (doc3 - frame3)
            |                           |                          |
       form1                  form2                 form3


assuming SDI: form2 would call the frame which would call OnButtonClick handler of form3.

assuming MDI: form2 would call frame2 wich would call main frame that calls frame3 which would call OnButtonClick handler of form3.

Sara
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.