Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2005

Tip: Looking for answers? Try searching our database.

Multiple Forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matthew Morvant - 14 Jan 2005 17:25 GMT
I have a C# application that starts off at a main form.  On this form are
several private variables with public properties (get/set).  One task
envolves a second form poping up and the data from that form is written out
to one of the public properties on the main form.  When a third form is
popped up the data that the second form set is no longer set.  Is there
something wrong with my thinking? Anyone have any recomendations for a
better method?  I just need variables that I can access/set from a number of
different locations.  This is my first major (GUI) application in C#, so be
gentle.

Matthew
Tom Krueger [MSFT] - 17 Jan 2005 18:40 GMT
Hello,

Would you be binding the properties in the main form to some data in the
other forms.  If so, when that third form pops up, there might not be data
and the binding would set the main form properties to nothing.  Other than
that I would need more info on how you are coding this.

Possible Solutions:

1) You could create Global properties in a seaparate class (ie
static/shared) then have all the forms get and set those.  The first
consideration here is that if you have multiple threads that can access
these variables you will need to make them thread safe.  The other thing is
if you want to have your forms update as the values change on these
properties you will need to setup an event to tell you when the value has
changed.  So in the set you will set the value of the property and call
PropertyNameChanged event which you created.  You could make it more generic
and call it DataChanged and have all your properties call a single event so
that your form only needs to listen to the one.

2) Add and event to the Second and Third form that you call when you want
data changed on the main form.  Have the main form listen to the events on
the second and third form.  You will probably want to create you own
EventArgs class that contains the data you need to pass back to the main
form.

3) The way you were doing it would seem fine.  Main form opens Second form.
Second form calls public set properties on the Main form.  Main form open
Third form.  Third form call properties on Main form.  If it is not the
binding issue I stated earlier, I will need more details to help.

Hope that helps,

Tom

Signature

Tom Krueger

My Blog - http://weblogs.asp.net/tom_krueger
Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility

This posting is provided "as is" with no warranties and confers no rights.

>I have a C# application that starts off at a main form.  On this form are
>several private variables with public properties (get/set).  One task
[quoted text clipped - 7 lines]
>
> Matthew

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.