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 / .NET Framework / New Users / October 2007

Tip: Looking for answers? Try searching our database.

transferring data between windows forms

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Yasin Cepeci - 16 Oct 2007 20:46 GMT
How can I transfer string like variables between two form(except txt file).
william.w.oneill@gmail.com - 17 Oct 2007 03:59 GMT
> How can I transfer string like variables between two form(except txt file).

There are many different ways to accomplish this if they are forms in
the same application (events, a mediator class that contains
references to both forms, passing one form as a reference to the
other, etc.) If they are in separate applications, something like this
helped me:
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_t
hread/thread/79281c06e28187c6/a5976bd3213090e0?lnk=gst&q=passing+message+between
+instance+mutex+bill#a5976bd3213090e0


Good luck
Ramses - 17 Oct 2007 11:42 GMT
Hi Yasin,

Create your child form as you would normally.

Modify the child form's constructor and add your own parameters (arguments).
One of these can be a reference to an object (such as a container class,
string, structure, ...) that contains the data you want to pass to your
form.

When you instantiate your child class in the parent class or form, you pass
a reference to the data object (or structure) to your child form's
constructor.

When the child form is instantiated, it will be able to access the data in
this data object.  It can also modify it, so when the child form is closed,
the parent can read (get access) to the modified data from the child form.

Example code (in VB).  The code is fairly similar in C# and C++:

Define the child form as below:

Public Class Form_Child

   Private m_Msg As String

   '
   ' Note: If you also want to modify the msg string so that the user
(parent) will
   ' see the change, pass msg ByRef instead of ByVal.
   '
   Public Sub New(ByVal msg As String)
       ' This call is required by the Windows Form Designer.
       InitializeComponent()

       ' Save the message string passed to us by the user.
       m_Msg = msg
   End Sub

   ' Use the String value (m_Msg) and modify it if required in the child
form.
   Public Sub Form_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) handle MyBase.Load
       MessageBox.Show("My name is " + m_Msg)
   End Sub

End Class

In the parent class:

   ...
   Dim myName As String = "Fred"
   Dim form As New Form_Child(myName)
   form.ShowDialog()
   form.Dispose()
   ...

Hope this helps.

Ramses

> How can I transfer string like variables between two form(except txt
> file).
Linh Tran - 24 Oct 2007 11:34 GMT

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.