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

new c# frustrations

im starting to think everything became A LOT more complicated with .net as
opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add text
to a textbox on form2.

sure was easy in vs6
Jul 20 '07 #1
9 1247
Looking through your previous posts, it may be an idea to spend some time
learning the differences between VB6 and VB.NET - they are small but
important. You've already asked how to access a button one form from
another - to which you've got an answer, now you're asking how to access a
text box in one form from another (note: they both inherit from control (and
therefore object), so same concepts apply). I could give you the answer
here, but I fear that I can see your next post now:

----------------
im starting to think everything became A LOT more complicated with .net as
opposed to vs6.
how can i access a listbox on a form from another form?
for example i have a button on form1 and when i click it i want to add an
item
to a listbox on form2.
sure was easy in vs6

----------------
"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
im starting to think everything became A LOT more complicated with .net as
opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6


Jul 20 '07 #2
On Jul 20, 9:31 am, "S Moran" <s...@moran.comwrote:
im starting to think everything became A LOT more complicated with .net as
opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add text
to a textbox on form2.

sure was easy in vs6
I think that having two forms directly communicate with each other is
generally a bad a model. I'm not sure I ever thought about doing this
with VS6 but I probably did it through VB6 just as a quick and dirty
hack.
I would highly recommend changing your model so if you click on a
button it talks to some other object which then fires an event which
the other form responds to. Then when you create both of those forms
they use that object as their conduit of communication. It really
shouldn't be a lot of code.

Jul 20 '07 #3
hhmm... apparently its not that simple? if textbox1 exists on form2, then
you would think, from button1 i could access the textbox via
"form2.textbox1.text", but this isnt working.

so howzabout a pointer? or is that not why we're here?


"Paul Hadfield" <no****@noone.comwrote in message
news:eP**************@TK2MSFTNGP05.phx.gbl...
Looking through your previous posts, it may be an idea to spend some time
learning the differences between VB6 and VB.NET - they are small but
important. You've already asked how to access a button one form from
another - to which you've got an answer, now you're asking how to access a
text box in one form from another (note: they both inherit from control
(and therefore object), so same concepts apply). I could give you the
answer here, but I fear that I can see your next post now:

----------------
im starting to think everything became A LOT more complicated with .net as
opposed to vs6.
how can i access a listbox on a form from another form?
for example i have a button on form1 and when i click it i want to add an
item
to a listbox on form2.
sure was easy in vs6

----------------
"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
>im starting to think everything became A LOT more complicated with .net
as opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6


Jul 20 '07 #4
You can if textbox1 is visible in form1. Designer usually makes control
fields private, so no visibility. You can change it to public.

But this is bad practice. Probably you need to familiarize yourself with
access modifiers and read about properties and fields. It's basic OO stuff,
which can help you to sort out issues like this one.

http://msdn2.microsoft.com/en-us/lib...sx(VS.80).aspx
"S Moran" <s@moran.comwrote in message
news:OH**************@TK2MSFTNGP03.phx.gbl...
hhmm... apparently its not that simple? if textbox1 exists on form2, then
you would think, from button1 i could access the textbox via
"form2.textbox1.text", but this isnt working.

so howzabout a pointer? or is that not why we're here?


"Paul Hadfield" <no****@noone.comwrote in message
news:eP**************@TK2MSFTNGP05.phx.gbl...
>Looking through your previous posts, it may be an idea to spend some time
learning the differences between VB6 and VB.NET - they are small but
important. You've already asked how to access a button one form from
another - to which you've got an answer, now you're asking how to access
a text box in one form from another (note: they both inherit from control
(and therefore object), so same concepts apply). I could give you the
answer here, but I fear that I can see your next post now:

----------------
im starting to think everything became A LOT more complicated with .net
as opposed to vs6.
how can i access a listbox on a form from another form?
for example i have a button on form1 and when i click it i want to add an
item
to a listbox on form2.
sure was easy in vs6

----------------
"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
>>im starting to think everything became A LOT more complicated with .net
as opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6



Jul 20 '07 #5
By default, controls are defined as "private" to a form.

In "form 1" (the one that has the text box), change the modifier on the text
box from "private" to "public". This will allow it to be visible.

The other problem you're going to run into is that VB6 used default form
instances, and .Net doesn't. This means when you create a "new" form 1 and a
"new" form 2, you'll need to keep the references around. This way form2 can
say:
myform1.UserNameTextBox.Text = "bla bla bla";

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
im starting to think everything became A LOT more complicated with .net as
opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6


Jul 20 '07 #6
thank you very much.
interesting, form2 has a textbox whose modifier is set to public...
in form1's class i have "Form secondform = new Form2();"
then, a button on form1 says "secondform.textBox1.Text = "some text here";
but this doesnt work. i get:

"Error 1 'System.Windows.Forms.Form' does not contain a definition for
'textBox1'

"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:u6**************@TK2MSFTNGP05.phx.gbl...
By default, controls are defined as "private" to a form.

In "form 1" (the one that has the text box), change the modifier on the
text box from "private" to "public". This will allow it to be visible.

The other problem you're going to run into is that VB6 used default form
instances, and .Net doesn't. This means when you create a "new" form 1 and
a "new" form 2, you'll need to keep the references around. This way form2
can say:
myform1.UserNameTextBox.Text = "bla bla bla";

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
>im starting to think everything became A LOT more complicated with .net
as opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6


Jul 20 '07 #7
ok... so changing "Form secondform = new Form2();"
to "Form2 secondform = new Form2();" fixed that problem.
trying to get a good understanding of why

"S Moran" <s@moran.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
thank you very much.
interesting, form2 has a textbox whose modifier is set to public...
in form1's class i have "Form secondform = new Form2();"
then, a button on form1 says "secondform.textBox1.Text = "some text here";
but this doesnt work. i get:

"Error 1 'System.Windows.Forms.Form' does not contain a definition for
'textBox1'

"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:u6**************@TK2MSFTNGP05.phx.gbl...
>By default, controls are defined as "private" to a form.

In "form 1" (the one that has the text box), change the modifier on the
text box from "private" to "public". This will allow it to be visible.

The other problem you're going to run into is that VB6 used default form
instances, and .Net doesn't. This means when you create a "new" form 1
and a "new" form 2, you'll need to keep the references around. This way
form2 can say:
myform1.UserNameTextBox.Text = "bla bla bla";

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
>>im starting to think everything became A LOT more complicated with .net
as opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6


Jul 20 '07 #8
This is inheritence. Form2 inherits from Form, so your original declaration
only opened the access to the base class methods.
"S Moran" wrote:
ok... so changing "Form secondform = new Form2();"
to "Form2 secondform = new Form2();" fixed that problem.
trying to get a good understanding of why

"S Moran" <s@moran.comwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
thank you very much.
interesting, form2 has a textbox whose modifier is set to public...
in form1's class i have "Form secondform = new Form2();"
then, a button on form1 says "secondform.textBox1.Text = "some text here";
but this doesnt work. i get:

"Error 1 'System.Windows.Forms.Form' does not contain a definition for
'textBox1'

"Chris Mullins [MVP]" <cm******@yahoo.comwrote in message
news:u6**************@TK2MSFTNGP05.phx.gbl...
By default, controls are defined as "private" to a form.

In "form 1" (the one that has the text box), change the modifier on the
text box from "private" to "public". This will allow it to be visible.

The other problem you're going to run into is that VB6 used default form
instances, and .Net doesn't. This means when you create a "new" form 1
and a "new" form 2, you'll need to keep the references around. This way
form2 can say:
myform1.UserNameTextBox.Text = "bla bla bla";

--
Chris Mullins, MCSD.NET, MCPD:Enterprise, Microsoft C# MVP
http://www.coversant.com/blogs/cmullins

"S Moran" <s@moran.comwrote in message
news:Ox*************@TK2MSFTNGP04.phx.gbl...
im starting to think everything became A LOT more complicated with .net
as opposed to vs6.

how can i access a textbox on a form from another form?

for example i have a button on form1 and when i click it i want to add
text to a textbox on form2.

sure was easy in vs6


Jul 20 '07 #9
S Moran <s@moran.comwrote:
thank you very much.
interesting, form2 has a textbox whose modifier is set to public...
in form1's class i have "Form secondform = new Form2();"
then, a button on form1 says "secondform.textBox1.Text = "some text here";
but this doesnt work. i get:

"Error 1 'System.Windows.Forms.Form' does not contain a definition for
'textBox1'
And indeed it doesn't. You've declared the type of secondform to be
Form - you should have declared it to be Form2. (Or preferrably, you
should have given Form2 a more sensible and meaningful name in the
first place.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jul 20 '07 #10

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

Similar topics

2
by: Adrienne | last post by:
This page validates XHTML-Strict and the CSS validates as well. Opera and Netscape 7.0 display it correctly. There should be a film strip on the left side, bordered in red, a list of links at...
4
by: Matthew Crouch | last post by:
As noted before, I'm not a JS programmer, but I ought to be able to get a couple simple things done with it and now I've spent two weeks on them. Main reasons: - seems like JS is all-or-nothing....
10
by: Sahil Malik | last post by:
This is a C# project. My code highlighting decides to dissappear randomly. With that goes away my intellisense, ability to copy paste, and my sanity. What is going on? - Sahil Malik...
4
by: AWesner | last post by:
For readability sake I’m going to first state that: LF = Line Feed CHR(10) CR = Carriage Return CHR(13) Since Rich Text Format is a standard formalized by Microsoft Corporation I get to ask...
3
by: Shawn Ferguson | last post by:
Hello All, I'm starting to learn C# and OOP to become a better programmer, however I;m getting frustrated. It's tough, but what is making it really tough for me is trying to do everything with...
0
by: =?Utf-8?B?d25kcmRvZw==?= | last post by:
1. what are the maximum number of guides available in PPt08? There seem to be separate limits on horiz and vert guides, and one I've maxed out (20 horiz + 20 vert?), the next guide I add deletes...
1
by: sean_walsh | last post by:
Hi From classic ASP, I had a custom error handling situation that was quite simple. Errors were all redirected to Error.asp. This page would check 2 settings, EmailErrorMessage and...
11
Airslash
by: Airslash | last post by:
Hi, I'm sorry if this is not the correct forum, but since I'm programming in C++ this looked like the best place. I'm trying to make a nice DLL file for the company where we place all...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.