943,888 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 800
  • VB.NET RSS
Dec 18th, 2008
0

help accessing control from a different form

Expand Post »
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
vb Syntax (Toggle Plain Text)
  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.

VB Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008
Dec 19th, 2008
0

Re: help accessing control from a different form

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 4:31 am.
Reputation Points: 84
Solved Threads: 58
Posting Pro in Training
waynespangler is offline Offline
461 posts
since Dec 2002
Dec 19th, 2008
0

Re: help accessing control from a different form

Ohhhh... I see. So creating a new instance of the form in memory basically erases the original. Makes sense. Thank you!
Reputation Points: 22
Solved Threads: 14
Junior Poster in Training
jbrock31 is offline Offline
73 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Open Browser from VB.NET
Next Thread in VB.NET Forum Timeline: Multithreaded / asynch SQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC