473,465 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

working with Textbox

I have been working on projects in vb5 and I am now trying to
get started with .net as you can see I am not doing very well.

I have a program that has two forms. On form1 I have a TextBox1.
From form2 I would like to write text to form1.TextBox1.text but
this does not work in .net. What changes do I need to make this work.

Jim
Nov 20 '05 #1
4 1367
"Tom McLaughlin" <tb***@cwnet.com> schrieb
I have been working on projects in vb5 and I am now trying to
get started with .net as you can see I am not doing very well.

I have a program that has two forms. On form1 I have a TextBox1.
From form2 I would like to write text to form1.TextBox1.text but
this does not work in .net. What changes do I need to make this
work.


If you want to access an object you need a reference. If you don't have a
reference it must be made available. This is usually done by passing it
using a public property or as a procedure argument.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #2
OK, I do want to access the TextBox1 on form1 so how would I
reference it so that form2 can write to it?
"Armin Zingler" <az*******@freenet.de> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
"Tom McLaughlin" <tb***@cwnet.com> schrieb
I have been working on projects in vb5 and I am now trying to
get started with .net as you can see I am not doing very well.

I have a program that has two forms. On form1 I have a TextBox1.
From form2 I would like to write text to form1.TextBox1.text but
this does not work in .net. What changes do I need to make this
work.


If you want to access an object you need a reference. If you don't have a
reference it must be made available. This is usually done by passing it
using a public property or as a procedure argument.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #3
"Tom McLaughlin" <tb***@cwnet.com> schrieb
I have been working on projects in vb5 and I am now trying to
get started with .net as you can see I am not doing very well.

I have a program that has two forms. On form1 I have a
TextBox1. From form2 I would like to write text to
form1.TextBox1.text but this does not work in .net. What changes
do I need to make this work.


If you want to access an object you need a reference. If you don't
have a reference it must be made available. This is usually done by
passing it using a public property or as a procedure argument.


OK, I do want to access the TextBox1 on form1 so how would I
reference it so that form2 can write to it?


It depends on the structure of the application.
- Is it an MDI application?
- Can there be multiple instances of the same Form?
- Are the Forms shown modally or modeless?
- Where are the Forms created?
- What's the relation between the Forms?
- Which types of Forms can be shown at the same time?
I assume that Form1 is the startup object and Form2 is shown modally:

Code in Form2:
Private m_Textbox As TextBox

Public Overloads Function ShowDialog( _
ByVal owner As System.Windows.Forms.IWin32Window, _
ByVal TextBox As TextBox) As DialogResult

m_Textbox = TextBox 'store reference to the textbox

Return MyBase.ShowDialog(owner) 'call procedure in base class

End Function

Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

m_Textbox.Text = "test"
End Sub

In Form1:
Dim f as new form2
f.Showdialog(me, Me.Textbox1)
That's only an example. You could also pass the textbox in the constructor
of Form2.
I prefer not passing controls to other Forms. You could pass the information
back from Form2 to Form1, so Form2 doesn't need a reference to Form1. This
is also the "better" OO way because it makes Form2 more abstract. I usually
do this with modal Forms.

Another way is to raise an event in Form2 and have Form1 catch it. Information
can also be passed when raising the event. This strategy I usually use with
modeless Forms.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #4
Tom,

I'm sure Armin will respond but in the interim... what he means is that you
need a "reference" to the form just like you need a reference to any other
object. It just doesn't exist in thin air. Form1 is the class name not
generally a reference to a form instantiated from the Form1 class.

You have to pass a reference to whatever you named your Form1 object (not
"Form1") to whatever you named your Form2 object (which wouldn't be
"Form2".) There are any number of ways to do this but whatever created
Form2 would have to tell it "this is Form1 if you want to reference anything
on it" and pass the variable that contains the Form1 object.

Have I made it worse :-)
"Tom McLaughlin" <tb***@cwnet.com> wrote in message
news:OS**************@TK2MSFTNGP09.phx.gbl...
OK, I do want to access the TextBox1 on form1 so how would I
reference it so that form2 can write to it?
"Armin Zingler" <az*******@freenet.de> wrote in message
news:e6**************@TK2MSFTNGP12.phx.gbl...
"Tom McLaughlin" <tb***@cwnet.com> schrieb
I have been working on projects in vb5 and I am now trying to
get started with .net as you can see I am not doing very well.

I have a program that has two forms. On form1 I have a TextBox1.
From form2 I would like to write text to form1.TextBox1.text but
this does not work in .net. What changes do I need to make this
work.


If you want to access an object you need a reference. If you don't have a reference it must be made available. This is usually done by passing it
using a public property or as a procedure argument.
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html


Nov 20 '05 #5

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

Similar topics

2
by: Scott Kelley | last post by:
I have a control inside of an asp:Table control. Once I place it in there, I can't seem to edit it any more (Double click to add events, drag to reposition, etc...). If I use an HTML table, no...
16
by: Joel Byrd | last post by:
I am having this ridiculous problem of trying to set the innerHTML of a div node. It works in all other browsers, but internet explorer is giving me an "Unknown runtime error". This is actually...
3
by: Dhana | last post by:
Hi All, I have developed one web application. In that I used aspnet web textBox control. I have set maxlength property for that text box 300 and TextMode property as multiline . When i typed...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
4
by: nkoier | last post by:
Hi, I've been going crazy trying to figure out what's wrong with our Asp.Net 2.0 intranet site. At the very top of our main page I provide a TextBox and a Button for submitting Google searches....
5
by: BSM | last post by:
Hi, I have used some validator controls in my project and itz working fine in developement enviro. But it does not work in the Live site. Help me to solve this issue. bsm
3
by: TS | last post by:
I am using IE 7. I have a website running on my local machine (localhost) and auto complete doesnt work for any of the textboxes, but going to web sites on the internet does support this so i know...
1
by: Jim in Arizona | last post by:
On one page I have a datalist where a message is bound to a label. On another page I have the datalist which allows for the insert of new message as well as being able to edit those messages. The...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.