Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Guest mutant
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...