Click here to Skip to main content
11,577,522 members (58,152 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
I have form open and i am going to another form creating data and again passing to the already open form...So rt now mulitple forms are coming,....How to avoid..Is it possible to pass data without show dialog in windows application c#....
Posted 5-Apr-13 4:11am
CHill60 at 5-Apr-13 10:14am
It's not clear what your problem is ... in what way is the other form "creating data" - if it's not capturing data from a user then why show it?
Richard MacCutchan at 5-Apr-13 10:15am
Change the visible property of the original form from True to False, and vice versa to get it back.
Sergey Alexandrovich Kryukov at 5-Apr-13 10:24am
It really depends.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

There are only two ways to display a form in .NET: Show and ShowDialog.
If you have multiple copies appearing then it is not the use of either that is the problem - it is that you are constructing new instances instead of using the same instance each time.

Create a private class level variable to hold your form instance:
private MyForm myForm;
Do not assign it a value.
When you want to show or update the data, check the value:
if (myForm == null)
    myForm = new MyForm();
    myForm.FormClosing += new FormClosingEventHandler(myForm_FormClosing);
...pass the data to your form properties
And clear the variable when the form is closed:
void myForm_FormClosing(object sender, FormClosingEventArgs e)
    ...collect your data from the form properties if necessary
    myForm = null;
Korathu 2 at 5-Apr-13 10:57am
can u make it more clear...
OriginalGriff at 5-Apr-13 11:03am
What part doesn't make sense? It's difficult to make things clearer when I don't know what you don't understand! :laugh:
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

It would be the best to avoid using multiple forms at all. You can have just one main form and never create more forms (I don't count few modal forms, used like dialogs). What you have as forms now could be turned panels or tab pages (using TabControl. This way, transitions from one "form" to another would be just hiding one panel and showing another one. With tab pages, it's even simpler: the user select the tabs needed at the moment, one at a time. Think about changing of your design this way; it will cover many cases.

A more advanced variant of the same thing would be the dockable UI, pretty much like in Visual Studio.


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 180
1 OriginalGriff 115
2 Richard MacCutchan 100
3 Abhinav S 90
4 Sergey Alexandrovich Kryukov 81
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 681
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375

Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100