Reference open form objects

tcl4p

Well-known member
Joined
Feb 29, 2008
Messages
48
Programming Experience
1-3
Can someone tell me how to reference objects i.e. procedures, events from one form to second form that is still open. For instance I call a form to add a value to the database, but I leave the calling form open. After the value is added/updated and the form is closed I'd like to refresh the calling form as if were going to be a fresh load. That is to say call the same procedures I called when the form was loaded.
In vb6 as long as the form was open you could reference objects(procedures,events) in the form as well as declare variables "public" and reference them from another another form. I can't seem to do this in vb.net and had to stick the variable in a module and declare them public.
Thanks for the help.

Tom
 
Hello.

I'm not sure if that's possible, since of you close the form it gets disposed. But you could try to catch FormClosing-Event of the form, cancel the event and hide the form with Visible = False.
Theoretically is the form only hidden, and the variables should be still accessable.

VB.NET:
    Private Sub YourForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        me.Visible = False
        e.cancel = True
    End Sub

Bobby
 
Thanks for reply

Bobby,
Thanks for the reply. Actually I'm not closing the form since I figured it had to remain open to access its objects. The question is how to I execute the calling forms load event when I closed the form that was closed, that is to say execute form 1's load even when I close form 2.

Thanks,
Tom
 
Hello.

I'm not sure if that's possible. But you could pull all the code in there into a Public Sub or Function. I'd say that that would be the clean way, 'cause you can call that Sub/Function from the Load-Event, and from other Forms.

Bobby
 
Back
Top