|
-
May 4th, 2004, 03:03 PM
#1
Form2 - access Form1's textbox [Resolved]
This must be real simple.
From form1, I call up form 2.
now, in form2, I'd like to MessageBox.Show the text in Form1's TextBox1.
I've obviously tried
VB Code:
MessageBox.Show Form1.Textbox1.Text
and that is wrong.
How do I access this property?
Last edited by mendhak; May 5th, 2004 at 03:51 PM.
-
May 4th, 2004, 03:26 PM
#2
OK, I created a module and declared both forms there. Then, it was pretty simple. The IDE complied, and I was happy.
-
May 4th, 2004, 03:30 PM
#3
Question: Is what I did the correct way?
-
May 4th, 2004, 03:45 PM
#4
Fanatic Member
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
May 4th, 2004, 07:32 PM
#5
Frenzied Member
It's fine. The only problem I've found with declaring the forms in a module is when you close a form, you can't reopen it. I had a main form that could call different forms. The secondary forms would get disposed of when they were closed.
Someone did post a workaround to it, passing the calling form to the secondary form, but I'd reworked the form by then.
-
May 5th, 2004, 03:36 AM
#6
Fanatic Member
umm ive always handled forms in module and have never come across the problem of not being able to reopen a form, i know you need to be careful when dealing with forms because you can open them when they dont really exist, all i can really say at this moment in time is if you close it make the module variable nothing then try reopening it
so use onclosing event
I am curretly building a defect management system for software and web developers,
If you wana try it out (beta test) and keep it for free just send me a message
-
May 5th, 2004, 07:07 AM
#7
PowerPoster
Hi,
"This must be real simple.
From form1, I call up form 2.
now, in form2, I'd like to MessageBox.Show the text in Form1's TextBox1."
Unless I'm crazy the answer IS real simple.
try
In form1
VB Code:
Dim frm2 As New fclsTest
frm2.TextBox2.Text = Me.TextBox1.Text
frm2.ShowDialog()
in form2 Load event
VB Code:
MessageBox.Show(TextBox2.Text)
Last edited by taxes; May 5th, 2004 at 07:17 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 5th, 2004, 07:16 AM
#8
PowerPoster
Hi,
You could also use:
In form1
VB Code:
Dim form2 as new fclsTest
form2.MesBox(me.TextBox1.Text)
form2.ShowDialog
In form 2
VB Code:
Public Sub MesBox(Message1 as String)
messagebox.show(Message1)
End Sub
I expect there are other ways also
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
May 5th, 2004, 09:49 AM
#9
Hyperactive Member
Dear Mendhak, the only not strange way (because often I like to use very personal strategy ) I have successfully tested in your situation, is declare Form1 as public, in a module. Form2 should be visible, anyway, from Form1, being declared and instanced inside it and so, if you need only to do like similar at what you described, Taxes suggestion is good (always if I well understand ):
Instance Form2 (inside Form1), then write into its controls or public variables what you need and then show it...or something similar. In this case you'd not need to put any form in a module.
Someone said to me a Form Child can access its father, but I've never used, nor verified, it.
Beg your pardon for my caotich english!
Live long and prosper (Mr. Spock)
-
May 5th, 2004, 10:39 AM
#10
Frenzied Member
Originally posted by carlblanchard
umm ive always handled forms in module and have never come across the problem of not being able to reopen a form, i know you need to be careful when dealing with forms because you can open them when they dont really exist, all i can really say at this moment in time is if you close it make the module variable nothing then try reopening it
so use onclosing event
Well, I get an error when I try it, saying the form's already disposed.
Module: declare form1 and form2. Show form1
form1: show form2
form2: blah blah, click the little X close button, return to form1
form1: show form2 -> error, form2 is disposed
I know I could eliminate the X button, Hide instead of Close, etc. But it's an error I get.
-
May 5th, 2004, 11:21 AM
#11
Hyperactive Member
Yes Salvelinus, if you close the form then you have to reinstance it, but now you do it locally (in Form1), not in a module, and the new instance will not be accessible from everywhere. Anyway this last condition should not be a problem for you. Stay valid that you can instance Form2 and at the next line you can write into it. Isn't it?
Live long and prosper (Mr. Spock)
-
May 5th, 2004, 11:35 AM
#12
Frenzied Member
I found it easier to just declare form2 in the form1 event that shows it. I don't really reference anything from one form on another that often.
-
May 5th, 2004, 03:50 PM
#13
Yes, I could also have passed the value to a public variable in Form2. I was wanting to avoid the hassle of having to do that though. Reminiscent of VB6 days
-
May 5th, 2004, 03:51 PM
#14
And thanks for your input, everyone.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|