Results 1 to 5 of 5

Thread: Access Form Controls from other class

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3

    Access Form Controls from other class

    Hi all:

    I Have 2 controls in Form1 (TextBox1 and Button1).
    TextBox1.Text = "111"

    Then I have a class (myClass.vb) that inherits Form1
    This class as a:

    Sub ChangeText()
    dim objForm1 as New Form1
    objForm1.TextBox1.Text = "222"
    End Text

    When I click on Button1 i want to go to the ChangeText() in the other class and change TextBox1.Text

    Function Button1_Click
    dim objmyClass as New myClass
    objmyClass.ChangeText()
    End Function


    But it doesn't work ..

    How can I change TextBox1 properties or other Control properties that are in Form1.vb from a Function that is in myClass.vb?

    Thanx in advance.
    B.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You'd have to pass in the instance of the form you are using ot the instance of the control and probably ByRef.

    See in this code:
    VB Code:
    1. Sub ChangeText()
    2. dim objForm1 as New Form1
    3. objForm1.TextBox1.Text = "222"
    4. End Text

    You are creating a whole new form and then changing the textbox in it. You need to work with the form that is already open. Try something like this:

    VB Code:
    1. Sub ChangeText(ByRef Sender as Object, e as System.EventArgs)
    2. dim frm as Form1
    3. frm=CType(Sender,Form1)
    4. frm.TextBox1.Text = "222"
    5. End Text

    I'm not sure that is correct but it should be something along that line. And when you call it use this:
    VB Code:
    1. Function Command1_onclick
    2. dim objmyClass as New myClass
    3. objmyClass.ChangeText(Me,Nothing)
    4. End Function

  3. #3
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hehe sou o oriondream da mIRC, tb andas por aki? pelos vistos este tipo sabe como o fazer

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2002
    Posts
    3
    thanx Edneeis that's it!

    Obrigado!

  5. #5
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yah funciona, yep it works

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