Electron Posted April 2, 2003 Posted April 2, 2003 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: 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: 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 Quote
*Gurus* divil Posted April 2, 2003 *Gurus* Posted April 2, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Electron Posted April 2, 2003 Author Posted April 2, 2003 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 Quote
Guest mutant Posted April 2, 2003 Posted April 2, 2003 change your class to this: 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.