help accessing control from a different form

Thread Solved

Join Date: Oct 2008
Posts: 32
Reputation: jbrock31 is an unknown quantity at this point 
Solved Threads: 1
jbrock31 jbrock31 is offline Offline
Light Poster

help accessing control from a different form

 
0
  #1
Dec 18th, 2008
Hello everyone. I have been studying VB on my own in prep for my class next semester. I am trying to update a label on form1 from form2. Below is just a "test" example i created to figure out what im doing wrong. It is not the actual project i am working on.

this is the form1 code
  1.  
  2. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.  
  4. Dim frm2 As New Form2()
  5.  
  6. frm2.Show()
  7.  
  8.  
  9. End Sub

this is the second form code. am i accessing this wrong or declaring something else incorrectly? If you need anymore info,let me know. All i have is one button on the first form opening the second form. This form has a button that when i click it, i want to update the label in form1. Thanks you in advance.

  1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.  
  3. Dim frm1 As New Form1()
  4.  
  5. frm1.lblTest.Text = "Hello"
  6.  
  7. End Sub
Reply With Quote Quick reply to this message  
Join Date: Dec 2002
Posts: 461
Reputation: waynespangler is on a distinguished road 
Solved Threads: 56
waynespangler waynespangler is offline Offline
Posting Pro in Training

Re: help accessing control from a different form

 
0
  #2
Dec 19th, 2008
Well, it depends. Are you destroying Form1 when you go to Form2? If you are then you are right. I feel though that you are not, so, what you have is Form1 and Form2 and then creating frm1.

Delete the line:
Dim frm1 As New Form1()
and change the next line to:
Form1.lblTest.Text = "Hello"

If you are using vb 2005 or vb 2008 then you don't need to create a new form. Just use:

Form2.Show()
Last edited by waynespangler; Dec 19th, 2008 at 3:31 am.
Wayne

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 32
Reputation: jbrock31 is an unknown quantity at this point 
Solved Threads: 1
jbrock31 jbrock31 is offline Offline
Light Poster

Re: help accessing control from a different form

 
0
  #3
Dec 19th, 2008
Ohhhh... I see. So creating a new instance of the form in memory basically erases the original. Makes sense. Thank you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum


Views: 670 | Replies: 2
Thread Tools Search this Thread



Tag cloud for VB.NET
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC