Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to I access my textbox controlls from another class

Posted on 2006-05-05
5
Medium Priority
?
393 Views
Last Modified: 2008-01-16
Hi Experts.

This might be a very simple question, but I need to access my controlls, ie, textbox, checkboxes and such from another class.  The controlls have been created using the Designer in VS, so by default they have Protected on them.  I can't seem to call them from my other classes. Any help?

Thank.
0
Comment
Question by:tomasz_k
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
tsay earned 2000 total points
ID: 16614668
For this you'll have to use Properties. Let's say you have a textbox called TextBox1. The TextBox1 is protected, this means that only the class itself, or classes which inherited from the class can access the textbox. You can however create a public property which can set/get the textbox text value or the checkbox value or what ever control you want. The reason for this is called encapsulation. It's to make sure that you have full control of what happens with the objects in your class. Every other class that wants to change the value of your control will have to use your public property and there you can do all the checks you want.

Code example:
=========

    Public Property myTextBoxValue() As String
        Get
            myTextBoxValue = me.yourtextbox.text
        End Get
        Set(ByVal Value As String)
          me.yourtextbox.text = Value
        End Set
    End Property

For a checkbox this could be

    Public Property myCheckBoxValue() As Boolean
        Get
           myCheckBoxValue = me.yourcheckbox.checked
        End Get
        Set(ByVal Value As Boolean)
           me.yourcheckbox.checked = Value
        End Set
    End Property

HTH!
0
 

Author Comment

by:tomasz_k
ID: 16614749
tsay,
This would work, but it just seems like so much overhead.  I'm looking at filling in a form that has about 20 fields, bunch of lists and checkboxes.  I was reading a bit out the Inherits options.  Anyway I could use that to my advantage?

0
 
LVL 5

Expert Comment

by:tsay
ID: 16614800
Any OO-programmer here will tell you this is the way to do it. You must not see it as overhead, it's lots of code for you to write but this won't effect your program.

Another option you can do is select the control on your form and change the Identifier property of the control to public but this way you'll have no control at all what is happening with your controls. This is the "quick and dirty" way to achieve what you want.
0
 

Author Comment

by:tomasz_k
ID: 16614915
Thanks for the help, but one more quick question about the Identifier property.  I have went to code behind page and change the property to Public , but once I made some more changes on the form, the property changed back to Protected :( Any ideas how I can make it stay at public?
0
 
LVL 5

Expert Comment

by:tsay
ID: 16614985
This is Microsoft telling you to use properties ;p
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question