Results 1 to 6 of 6

Thread: [02/03] Access controls of other forms

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    167

    Question [02/03] Access controls of other forms

    I have Form1(Textbox1, Button1) and Form2(Textbox2).
    When I click Button1 of Form1, it will display Form2. In Form2, i want to access the Textbox1(any controls) of Form1. Any solution?

  2. #2
    Hyperactive Member nothingofvalue's Avatar
    Join Date
    Jul 2005
    Location
    Arizona
    Posts
    489

    Re: [02/03] Access controls of other forms

    Form1.Textbox1
    "Imagination is more important than knowledge..."

    Albert Einstein
    -----------------------------------------------
    If my reply helped you then you really were lost, but I still took the time to help, please rate it anyway

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [02/03] Access controls of other forms

    In VB.NET all forms are classes and form instances are just objects. One thing you could do is pass a reference to the first form in the constructor of the second, so when you show it it already has knowledge of the first form.

    One key principle to correct object-oriented design is scope - you shouldn't give anything a higher scope than needed.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [02/03] Access controls of other forms

    VB Code:
    1. Public Class Form2
    2.   Public Sub New(ByRef frm As Form2)
    3.     frm.TextBox1.Text="Welcome"
    4.   End Sub
    5. End Class
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2005
    Posts
    167

    Question Re: [02/03] Access controls of other forms

    Thanks. Why in VB 2005 we can use FormName.AnyControl without declare an instance of form? Is it shared member or something else?

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [02/03] Access controls of other forms

    You are referring to My.FormName, which is an instance of the form
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

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