473,396 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Accessing a Form control from a class

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
6 1147
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
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
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
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

Thanks Terry I will gove it a go
Nov 21 '05 #6
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
3
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
1
by: tmaster | last post by:
Within a class, can I create a property that is a listview? Here's what I tried, but it doesn't seem to work: '------------ create property to give the second form access to the first form's...
9
by: Blake Weaver | last post by:
Ok, this is probably a no-brainer for most of you but its escaping me and I can't even seem to find the answer in any documentation. How do you access a friend variable of one class, from another...
6
by: Adrian | last post by:
Hi I'm building an ActiveX replacement in VB.net base info from http://www.vbdotnetheaven.com/Code/Jun2003/2067.asp Anyone know how I can call a JavaScript Function in the hosting webpage from...
6
by: evandelagrammaticas | last post by:
Hi all. I have spent the better part of a day scouring the newsgroups and I am sure that I must have come across the solution a number of times - but I am still a real newbie at asp.net so please...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: aakash | last post by:
Hello Guys I am upsizing ms access project to give it a ms sql connectivity I am having problem in accessing form control values in ms sql function CREATE FUNCTION "ReportList DateRange"() ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.