By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,697 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,697 IT Pros & Developers. It's quick & easy.

Accessing a Form control from a class

P: n/a
Hi All

I am trying to access a control on my main form from a class. The control
is a Windows Media Player which I do not think I can instantiate in code.
The class needs to pass the file name to play. I am new to VB.Net, but not
to Basic or OOP, so I am sure that I am missing something obvious. I have
tried to access the forms controls using the form name 'form1.' but the
list I get does not contain any controls. I think all the controls should
be accessible.

Any help much appreciated

Jon
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Where is your class defined and instaniated ?
--
Terry Burns
http://TrainingOn.net
"Jon Masterson" <ne**@scruffyduck.co.uk> wrote in message
news:1q******************************@40tude.net.. .
Hi All

I am trying to access a control on my main form from a class. The control
is a Windows Media Player which I do not think I can instantiate in code.
The class needs to pass the file name to play. I am new to VB.Net, but
not
to Basic or OOP, so I am sure that I am missing something obvious. I have
tried to access the forms controls using the form name 'form1.' but the
list I get does not contain any controls. I think all the controls should
be accessible.

Any help much appreciated

Jon

Nov 21 '05 #2

P: n/a
Where is your class defined and instaniated ?


on the form. I had it instantiated in a separate global module but moved
itto the form. What I find odd is that none of the controls on the form
show up in the drop list that appears after form1.

Jon
Nov 21 '05 #3

P: n/a
Where is your class defined and instaniated ?


on the form. I had it instantiated in a separate global module but moved
itto the form. What I find odd is that none of the controls on the form
show up in the drop list that appears after form1.

Sorry - not sure I answered that correctly. The class (InterpreterClass)
is defined in it's own file (interpreter.vb) not in the form code. It is
intantiated in the form code along with the other variables for the form:

Public interpreter As New interpreterClass

Jon
Nov 21 '05 #4

P: n/a
OK, this is ONE way . . .

Create a constructor which will take a reference of the type form1. On your
form create a button and a textbox for demonstration purposes. The Textbox
instance is named TextBox1 in this example.

In the button

Dim ic As New InterpreterClass(Me)

When you press the button you pass the reference to the current form using
'Me' and as you can see in the constructor of the class you can then refer
to the parent form

Public Class InterpreterClass

Sub New(ByVal f As Form1)

f.TextBox1.Text = "Ive just been instantiated"

End Sub

End Class
--
Terry Burns
http://TrainingOn.net
"Jon Masterson" <ne**@scruffyduck.co.uk> wrote in message
news:qh*****************************@40tude.net...
Where is your class defined and instaniated ?


on the form. I had it instantiated in a separate global module but moved
itto the form. What I find odd is that none of the controls on the form
show up in the drop list that appears after form1.

Sorry - not sure I answered that correctly. The class (InterpreterClass)
is defined in it's own file (interpreter.vb) not in the form code. It is
intantiated in the form code along with the other variables for the form:

Public interpreter As New interpreterClass

Jon

Nov 21 '05 #5

P: n/a

Thanks Terry I will gove it a go
Nov 21 '05 #6

P: n/a
Cool, hope that helps.

Terry Burns
http://TrainingOn.net

----------------------------------------------------------------------------

"Jon Masterson" <ne**@scruffyduck.co.uk> wrote in message
news:mg******************************@40tude.net.. .

Thanks Terry I will gove it a go

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.