By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 911 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.tvw Admin.SelectedNode,
TreeViewAction.ByMouse)

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

Thanks,
Dean Slindee


Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <e7**************@TK2MSFTNGP11.phx.gbl>, Dean Slindee wrote:
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.tvw Admin.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
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2

P: n/a
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.

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.