Question and Problem

Electron

Newcomer
Joined
Mar 8, 2003
Messages
7
I have a form with a control on it and a class. I want to call the class and then in the class change one of the controls properties without creating a new form.

This is the code in the class:
Visual Basic:
Public Class Test
    Sub Change()
        Dim f As New Form1()
        f.cmdStart.Text = "Worked"
        f.Show()
    End Sub
End Class

This is the code in the form:
Visual Basic:
Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
        Dim t As New Test()
        t.Change()
End Sub

This is a very simple test so I know how to use it and then can apply it to a more complex program

Thanks a head of time
Electron
 
Change your Change subroutine to accept a parameter of type Form1, and then call it from the form passing Me. You can then adjust the form's instance to your heart's content.
 
Sorry, I am somewhat new to VB.Net. Could you give me some code on how to do that?

Thanks
This is very much appreciated

Electron
 
change your class to this:

Visual Basic:
Public Class Test
    Sub Change(ByVal f as Windows.Forms.Form)
        f.cmdStart.Text = "Worked"
        f.Show()
    End Sub
End Class

Now you just have to pass in the name of the form when calling this, you probably will use Me as the form name.
 
Back
Top