Shorter syntax to refeence another form's controls/events?

D

Dean Slindee

I have two different independent forms that need to talk to one another to
syncronize
their displays.

Is there a shorter way of referring to another form's controls/events than
creating a class or utilizing an ArrayList to hold references to the forms,
adding a form item to the array each time a new form is
loaded, and then looping thru the class of forms to find the reference?

'clsForm is a class similar to an ArrayList
Public Class frmMain
Private Sub frmMain_Load
clsForm.Add(Me)
End Sub
End Class

Public Class frmAnother
Private Sub frmAnother_Load
arrForm.Add(Me)
End Sub

Private Sub frmAnother_AnyEvent
Dim frm As Form
For Each frm In clsForm
If frm.Name = cfrmMain Then
Dim frmMain As frmMain = frm
Dim etvw As New
System.Windows.Forms.TreeViewEventArgs(frmMain.tvwAdmin.SelectedNode,
TreeViewAction.ByMouse)

Call frmMain.tvwAdmin_AfterSelect(Me, etvw)
Exit For
End If
Next
frm = Nothing
End Sub
End Class

Thanks,
Dean Slindee
 
T

Tom Shelton

I have two different independent forms that need to talk to one another to
syncronize
their displays.

Is there a shorter way of referring to another form's controls/events than
creating a class or utilizing an ArrayList to hold references to the forms,
adding a form item to the array each time a new form is
loaded, and then looping thru the class of forms to find the reference?

'clsForm is a class similar to an ArrayList
Public Class frmMain
Private Sub frmMain_Load
clsForm.Add(Me)
End Sub
End Class

Public Class frmAnother
Private Sub frmAnother_Load
arrForm.Add(Me)
End Sub

Private Sub frmAnother_AnyEvent
Dim frm As Form
For Each frm In clsForm
If frm.Name = cfrmMain Then
Dim frmMain As frmMain = frm
Dim etvw As New
System.Windows.Forms.TreeViewEventArgs(frmMain.tvwAdmin.SelectedNode,
TreeViewAction.ByMouse)

Call frmMain.tvwAdmin_AfterSelect(Me, etvw)
Exit For
End If
Next
frm = Nothing
End Sub
End Class

Thanks,
Dean Slindee

If you make your forms collection a hashtable, then you can avoid the
loops. And the hashtable lookup is really quite fast.

If cForms.Contains("MainForm")
Dim frm As Form = cForms("MainForm")
Dim evt As TreeViewEventArgs

With frm
evtw = new TreeViewEvnetArgs( _
.tvwAdmin.SelectedNode, _
TreeViewAction.ByMouse)
.tvwAdmin_AfterSelect(Me, etvw)
End With

End If

HTH
 
P

Peter Huang

HI Dean,

I have replied to your another post in the same newsgroup.
Its title is as follows.
Subject: Shorter way to refer to another forms controls/events?
If you have any concern on this issue,please post here.

Regards,
Peter Huang
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