472,977 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,977 software developers and data experts.

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 3635
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
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
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
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
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
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
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
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
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
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
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.