Results 1 to 4 of 4

Thread: Simple VB.NET control question

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Location
    Illinois
    Posts
    20

    Simple VB.NET control question

    Hi everyone,

    I know that there is probably a very easy way to do this, but I have yet to figure it out. Here is the basic scenario:

    Form1 contains Label1
    Form1 creates an instance of Form2

    Form2 contains Button1
    Form2.Button1.onClick needs to set Form1.Label1.Text = "something" (without creating a new instance of Form1 because I need to keep all other values as-is).

    Your help is appreciated. Thanks!

    -Chris

  2. #2
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    I am thinking of using a module and using a public variable.

    Hmm..

    I'm going to have to do something like this with my program soon. I got a form that needs to manipulate, find and goto an area within the textbox on the other form.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You should try searching first:
    http://www.vbforums.com/showthread.p...hreadid=251839

    http://www.vbforums.com/showthread.p...hreadid=249630

    Although these do different things they show how to interact with multiple instance of forms, which is the same situation you have. You need to work with an existing instance of a form.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jul 2003
    Location
    Illinois
    Posts
    20
    I found the solution to my problem. In case anyone is interested:

    VB Code:
    1. Public Class Form1
    2.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         Dim f2 As New Form2()
    4.         f2.Create(Me)
    5.     End Sub
    6. End Class
    7.  
    8. Public Class Form2
    9.     Private m_fParent As Form1
    10.  
    11.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    12.         m_fParent.Label1.Text = "something"
    13.     End Sub
    14.  
    15.     Sub Create(ByVal fParent As Form1)
    16.         m_fParent = fParent
    17.         Me.Show()
    18.     End Sub
    19. End Class

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width