473,480 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Passing textbox value to another form

Hello Marc Gravell and Machin.
Good Day.

Why your not using an Instance in the form and yet your using a New Form?
Im using it because I want to open a single form only. If Im using a New
Form1, In my command button If I will click the button to show the Form1 it
will show the Form1 equal the click in the button.
What you suggestion to me. Im new in programming in C#.

Thanks.
--
To be Happy is To be Yourself
"Marc Gravell" wrote:
Simply create a property on Form2 that makes this possible:

public string CaptionText {
get {return textbox1.Text;}
set {textbox1.Text = value;}
}

and assign it:

sForm.CaptionText = textbox1.Text;
sForm.Show();

For the record, I also don't recommend this Form2 Instance() approach;
I'd simply use a new frmNEmp();

A static form, in particular, has various issues with threading,
multiple parenting, etc...

Marc
Jun 27 '08 #1
1 3652
On Fri, 11 Apr 2008 18:42:01 -0700, Saimvp
<Sa****@discussions.microsoft.comwrote:
Hello Marc Gravell and Machin.
Good Day.

Why your not using an Instance in the form and yet your using a New Form?
Im using it because I want to open a single form only. If Im using a New
Form1, In my command button If I will click the button to show the Form1
it
will show the Form1 equal the click in the button.
It seems to me that if you follow the general rule to always run your GUI
code on the original main GUI thread, Marc's concern about threading is
something you can safely ignore. I mean, it's a legitimate concern, but
it would only come up if you start trying to manipulate your user
interface from more than one thread. That's a good thing to avoid anyway.

Now, as far as other issues that might exist, Marc's pointed out one
other, specifically "multiple parenting". That is, if you want to provide
a parent for the form, then having just one form instance can lead to
problems if you wind up trying to show the form with more than one parent,
since all controls, including forms, can have only one parent. In your
sample code, you appear to be using the form as an MDI child form, which
may make this problem more of an issue. If you create a new instance each
time you want to show the form, this problem is avoided entirely.

Another issue has to do with resource management. Since you are showing
the form modelessly, when it's closed all, the form will be disposed.
This can be circumvented by changing all of the "close" logic in the form
so that the form is actually hidden, but doing that is a bit of a pain.
Again, creating a new instance each time you want to show the form avoids
the problem entirely.

It's not that there aren't reasons to design a form as a singleton. One
advantage is that the form can preserve its state very easily doing so,
without adding any extra code to save and restore the state for each new
instance. Another advantage is that if you are using the form in a way
such that it might already be visible and you want that existing form to
be used when the button is clicked, using a singleton is a convenient way
to do that.

But there are disadvantages, including those mentioned above. You should
consider whether the need for a singleton outweighs the disadvantages. In
most cases, it won't. In some cases, the best way to address your overall
design is to make the form a singleton.

It's not that there's a 100% rule. It's just that without knowing
anything else about your application, chances are that implementing the
form as a singleton is overkill and might needlessly complicate your
design in other areas.
What you suggestion to me. Im new in programming in C#.
Well, I think the suggestion Marc was making was to just create a new
instance of the form class each time you want to show it. Rather than
making the class follow the singleton pattern, don't bother with that and
just call "new frmNEmp()" to get a new instance each time you want it to
be shown.

Pete
Jun 27 '08 #2

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

Similar topics

6
2093
by: Robert Rozman | last post by:
Hi, I'm total php newbie and probably have trivial problem. I have following two scripts. First creates web form and should run second script with two arguments. But those two arguments don't...
2
2199
by: Timmins | last post by:
I have a date in a frame/page that i want to pass to another page. I can succefully pass a static value, i just can't pass a value from a text box. I tried to make everything public. I believe...
0
1284
by: Steve Wark | last post by:
I'm trying to develop a lookup form in asp.net (vb), when a button is clicked a small search form will open in a second window which will display a list of values. When a value is selected the...
3
1877
by: Vaughn | last post by:
In my MDI, I have a child form (frm_emp) that on a button click, displays another child form w/ a listview (frm_list). I had two questions: 1) Assuming I already have the emplcode the user...
11
3455
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...
8
4393
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...
1
2208
by: billy | last post by:
Ok, here's the situation... I have a user control that contains two textboxes (one for a from date/time and one for a to date/time) and two image buttons. The user control itself is supposed to...
6
1200
by: RBCC | last post by:
Public Class fraction Dim m_numerator As Int16 Dim m_denominator As Int16 Public Event zerodenom() Public Property numerator() As Int16 Get Return m_numerator
4
1642
by: campwes | last post by:
Hi! I have what I hope is a simple problem. I have 2 web forms. The first form is a welcome page with a textbox and button (in a user control). What's supposed to happen is that a user will...
4
1267
by: BrendanMcPherson | last post by:
Hi whats the easiest way to pass text from one page to another. I have a form on one page that has a textbox and "go" button. when the user selects Go, i would like it to go to another window...
0
7044
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
6908
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
7045
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
5341
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,...
1
4782
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...
0
4483
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
2995
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...
0
2985
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.