?
Solved

Access another forms properties or events...

Posted on 2005-03-28
13
Medium Priority
?
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month13 days, 19 hours left to enroll

801 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