Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Access another forms properties or events...

Posted on 2005-03-28
13
Medium Priority
?
168 Views
Last Modified: 2010-04-23
I have just started VB.NET from VB6. I need to know  how to access another forms events/controls, etc like you could in vb6. I.E.
In a form called form1:

Sub command1_click
form2.visible = True
End sub

or vice versa
I have tried somethign like
Public frm1 as Form1
frm1.visible = true
and can access what i need but when the code runs i get an error about referencing a null object.   Please help.
0
Comment
Question by:nongravity
  • 8
  • 5
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13646658
For you to access properties on a form, they would need to be defined as Shared, otherwise you would need an instance of the form:

Public Shared TotalCount() As Integer

or

Dim frm As Form2

If frm Is Nothing Then
  frm = New Form2
End If

Bob

0
 

Author Comment

by:nongravity
ID: 13646750
I've tried that. And when the button is clicked on form2 it errors out and gives me the error message about referencing a null object. (refering to Dim frm as Form2)
On blank form with a button I added this

button1_click
form2.button1.enabled = true

when this event fires I get that error message
0
 

Author Comment

by:nongravity
ID: 13646769
forgot to mention that the button is on form1
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:nongravity
ID: 13646797
geeez, I really need to think of everything to say before i press submit...
I changed the property from private to shared and I can access it that way but I would like to have access to all buttons, menus, controls, etc without having to change each event to "Shared" if possible. I am also upping the points on this to 325 because of my shear noobness to .net
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13646823
Are you instantiating a new Form2?  If not, then you will get the ubiquitous 'Object variable or with block not set' error.

frm = New Form2

Bob
0
 

Author Comment

by:nongravity
ID: 13651929
No, I'm not instancing a new form2.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13651945
Well, you're gonna need to if you want to access any of its properties.

Bob
0
 

Author Comment

by:nongravity
ID: 13652507
Ok, I understand that now but I can't access form1's properties,events, etc  from form2
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13652524
Is Form2 a sub-form from Form1, or does it stand by itself?

Bob
0
 

Author Comment

by:nongravity
ID: 13652567
Sorry for being clear as mud on this problem...lol.  Its an Mdi app. I create new instances of the "template" forms and can access those from Form1. But on certain events in the Child forms I need update the menu on the Parent form or "Form1". Hope this helps.
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 13652612
From Form2:

Dim parent As Form1 = Me.ParentForm
parent.Visible = False

Bob
0
 

Author Comment

by:nongravity
ID: 13652650
It works exaclty how I need it to.    THANK YOU!!!!!!
0
 

Author Comment

by:nongravity
ID: 13652800
Bob,
how would you do the same thing if its not an mdichild?
I will start another thread and give more points if you want.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question