Click here to Skip to main content
Rate this: bad
good
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 5:11am
Comments
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.
—SA
Rate this: bad
good
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
myForm.Show();
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;
    }
  Permalink  
Comments
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
good
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.
 
—SA
  Permalink  

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

  Print Answers RSS
0 DamithSL 425
1 OriginalGriff 184
2 BillWoodruff 170
3 Zoltán Zörgő 165
4 Maciej Los 163
0 OriginalGriff 7,854
1 DamithSL 5,949
2 Sergey Alexandrovich Kryukov 5,449
3 Maciej Los 5,084
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 5 Apr 2013
Copyright © CodeProject, 1999-2014
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