473,406 Members | 2,345 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,406 software developers and data experts.

declare a form so that you can reference it's controls

Here's what I'm trying to do in vb.net 2005.

I have a public declared method that sets the value of a control on a
form, but that form could change, so I don't want to code its actual
name. I want it to be a parameter in the module method so that you
pass the form name of whatever form called the method.

So let's say we call the method from form 1:

UpdateText(frmName)
Then in the module we have the actual method

Public Sub UpdateText(ByVal frmName as Form)

frmName.textbox1.text = "Hi, I'm Me."

end Sub

Now, the problem that arises is that frmName gets underlined by visual
studio and says: TextBox1 is not a member of
'System.Window.Forms.Form'. So apparently my parameter in the method
is wrong. But I can't find out what type the form should be. Can
anyone help me?

Thanks
Jul 4 '08 #1
2 1086

TextBox1 is not a member of System.Windows.Forms.Form - it is a member
of the Form1 class, which is a subclass of System.Windows.Forms.Form.
Try this:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Utilities.SetControl(Me, \"ExampleText\")
End Sub
End Class

Public Class Utilities
Public Shared Sub SetControl(ByRef MyForm As Form1, ByVal
MyTextVal As String)
MyForm.TextBox1.Text = MyTextVal
End Sub
End Class

If you need the flexibility to set the text of forms that are of class
Form1, then pass a reference to the control instead of the form, like
this:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Utilities.SetControl(Me.TextBox1, \\"ExampleText\\")
End Sub
End Class

Public Class Utilities
Public Shared Sub SetControl(ByRef MyTextBox As TextBox, ByVal
MyTextVal As String)
MyTextBox.Text = MyTextVal
End Sub
End Class
--
breitak67
Jul 5 '08 #2
On Jul 4, 8:30*pm, breitak67 <gu...@unknown-email.comwrote:
TextBox1 is not a member of System.Windows.Forms.Form - it is a member
of the Form1 class, which is a subclass of System.Windows.Forms.Form.
Try this:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Utilities.SetControl(Me, \"ExampleText\")
End Sub
End Class

Public Class Utilities
Public Shared Sub SetControl(ByRef MyForm As Form1, ByVal
MyTextVal As String)
MyForm.TextBox1.Text = MyTextVal
End Sub
End Class

If you need the flexibility to set the text of forms that are of class
Form1, then pass a reference to the control instead of the form, like
this:

Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Utilities.SetControl(Me.TextBox1, \\"ExampleText\\")
End Sub
End Class

Public Class Utilities
Public Shared Sub SetControl(ByRef MyTextBox As TextBox, ByVal
MyTextVal As String)
MyTextBox.Text = MyTextVal
End Sub
End Class

--
breitak67
Thank you very much for the help. Most appreciated!
Jul 24 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Soryt | last post by:
Hi everyone ! 1) An example from help: "Each Form object has a Controls collection, which contains all controls on the form. You can refer to a control on a form either by implicitly or...
8
by: Johm | last post by:
In my codes i am often referring to one and the same controls.Is it possible to declare these controls only once and then insert them in all my functions and subs? For example, i am often...
3
by: Chris | last post by:
Hi, I'm trying to append text from another class to a generic richTextBox that I've added to a Windows form. I can't seem to figure out how to expose the richTextBox to append text to it. ...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
7
by: Max | last post by:
How do I declare in the parent page's code behind a user control? I want to call a sub that is located in the user control. Want to do something like this: Call MyUserControl.MySub()
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
19
by: Coward 9 | last post by:
HI, I saw in an example hello.aspx, there is a <form tagbeing used like <form runat="server> I search all html tag references and could NOT find "runat" attributes for <formtag. which...
16
by: Mike | last post by:
Hi, I have a form with some controls, and a different class that needs to modify some control properties at run time. Hoy can I reference the from so I have access to its controls and...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.