How to access method in open form from another form.

  • Thread starter Thread starter twick10
  • Start date Start date
T

twick10

Hi,

I am trying to execute a control method on an open form (not with focus)
from a modal dialog box. I want to increment the node selected from the
dialog when a certain key is pressed.

Any help appreciated.

Robert T
 
* "twick10 said:
I am trying to execute a control method on an open form (not with focus)
from a modal dialog box. I want to increment the node selected from the
dialog when a certain key is pressed.

You will have to make a reference to the other form available to your
form. This can be done by setting a property to the other form when
instantiating the dialog from within the main form.
 
I'm not sure I follow the recommendation. Can anybody clarify. Perhaps
with some sample code?

Robert
 
This is how I like to do it:

' In a module:
Friend FormMain As frmNAME ' The name of the main form

' Main Form Load:
FormMain = Me

' Inside the open dialog, you can access your main form using
FormMain.
 
Add another constructor to the dialog form that accepts the main form as a
parameter:
Private _frmCalling As Form1
Public Sub New(ByVal frmCalling As Form1)

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

_frmCalling = frmCalling

End Sub

You can then use the reference to the main form to access controls on that
form from the dialog

For example, in the click event of a button on the dialog, you could do the
following
_frmCalling.TextBox1.Text = "Set from form2"

which would change the text property of the textbox on the main form.

I'm not exactly sure what you are trying to change on the main form but this
should give you an idea of what to do.

-Mike
 
Thanks, Jay

Works like a charm

Bob


Jay Feldman said:
This is how I like to do it:

' In a module:
Friend FormMain As frmNAME ' The name of the main form

' Main Form Load:
FormMain = Me

' Inside the open dialog, you can access your main form using
FormMain.
 
Back
Top