|
-
Nov 4th, 2003, 12:41 PM
#1
Thread Starter
Addicted Member
Access another form's objects
Is there a way I can access another form's objects or instances without passing them through a function or sub routien? Here's my situation.
I have a frmMain form that contains all my objects: buttons, panels, text boxes, datagrid, dataset and dataadapter etc.. Then I added a another class component, clsEvent, to my project. In this class, I want to be able to access all those objects in the frmMain form without passing them through a public shared sub. Is there a way? If there is way, mind give me a hand on this issue?
Any help is greatly appreciated!
ljCharlie
-
Nov 4th, 2003, 12:48 PM
#2
You should pass the current instance of frmMain to clsEvent, preferably in the constructor.
-
Nov 4th, 2003, 01:11 PM
#3
Thread Starter
Addicted Member
Many thanks for your help. But how do I do that?
ljCharlie
-
Nov 4th, 2003, 01:31 PM
#4
VB Code:
'in clsEvent
'store a local reference to a frmMain type
Private _frm As frmMain
'make constructor for passing it in
Public Sub New(form as frmMain)
'assign instance to local reference
_frm=form
'now you can refer to anything on frmMain by using _frm inside the class
End Sub
'example
Public Sub ShowText()
Msgbox(_frm.TextBox1.Text)
End Sub
'in frmMain when creating clsEvent
Dim ce As New clsEvent(Me)
-
Nov 4th, 2003, 01:42 PM
#5
Thread Starter
Addicted Member
Again, many thanks for the help.
Where in frmMain do I put this line: Dim ce As New clsEvent(Me)
And what is it for?
ljCharlie
-
Nov 4th, 2003, 02:02 PM
#6
That should be wherever you are creating the clsEvent object, which I guess doesn't have to be in frmMain but if its not then use the current instance of frmMain instead of ME in the constructor.
-
Nov 4th, 2003, 02:10 PM
#7
Thread Starter
Addicted Member
Thanks! Any variable or instance I declared as Private in the frmMain can not be accessed through this constructor, correct? Another words in frmMain I declared:
Private tableStyle1 As New DataGridTableSytle()
Can not be accessed in clsEvent as _frm.tableStyle1 right?
ljCharlie
-
Nov 4th, 2003, 02:25 PM
#8
That is correct since it has private scope then it can't be accessed outside of the form.
-
Nov 4th, 2003, 02:41 PM
#9
Thread Starter
Addicted Member
That is it! Thank you very much for the time you spent helping me.
ljCharlie
-
Nov 4th, 2003, 03:28 PM
#10
Thread Starter
Addicted Member
Sorry to bother you again, but I encounter a problem. In the clsEvent class, it seemed that I have to declared my routine as Private Sub and not Private Shared Sub for the constructor to work. So the question is, how do I call the sub routine in the frmMain form since it is not Shared?
ljCharlie
-
Nov 4th, 2003, 03:37 PM
#11
Thread Starter
Addicted Member
I think I got it.
ljCharlie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|