How to use data on two forms

  • Thread starter Thread starter imarkic
  • Start date Start date
I

imarkic

I have two forms. A button on form1, and when i click on button1 my
form1, form2 is open. Add some data to form2, and write it on form1,
all with class.
How to do that?
 
I have two forms. A button on form1, and when i click on button1 my
form1, form2 is open. Add some data to form2, and write it on form1,
all with class.
How to do that?

This really depends on the model you are using. In general, you will not
control it from an outside class. Instead, you will fill the second form
if it is child (MDI window is a good example) or raise events to get the
other direction.

There are other ways, but you will often end up with a tightly coupled
system if you try them, which is not good.

Peace and Grace,


--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
But could you give me example. I understand objects, inheriance but
there i have confusing
 
imarkic said:
But could you give me example. I understand objects, inheriance but
there i have confusing

I hook up with Gregory. It depends...

The main difference is whether you show Form2 modally (ShowDialog)
or modeless (Show). If Form2 is modal, you can still access the controls
on Form2 from Form1 after Form2 has been closed. Example:

using f2 as new form2
if f2.showdialog = dialogresult.ok
me.textbox1.text = f2.combobox1.text
end if
end using


Otherwise I could write a lot more, but it depends on what exactly
your goal is. As Gregory wrote, you can raise an event inside Form2
and handle it inside Form1. You can access the controls of Form2
or you can add properties to Form2 that return what you need.
Or the data can be passed as arguments of the event handler.


....

Here's a walkthrough for dialog boxes:
http://msdn.microsoft.com/en-us/library/cakx2hdw.aspx
 
I0ve succede but now with members of my class!

I hook up with Gregory. It depends...

The main difference is whether you show Form2 modally (ShowDialog)
or modeless (Show). If Form2 is modal, you can still access the controls
on Form2 from Form1 after Form2 has been closed. Example:

   using f2 as new form2
      if f2.showdialog = dialogresult.ok
         me.textbox1.text = f2.combobox1.text
      end if
   end using

Otherwise I could write a lot more, but it depends on what exactly
your goal is. As Gregory wrote, you can raise an event inside Form2
and handle it inside Form1. You can access the controls of Form2
or you can add properties to Form2 that return what you need.
Or the data can be passed as arguments of the event handler.

...

Here's a walkthrough for dialog boxes:http://msdn.microsoft.com/en-us/library/cakx2hdw.aspx
 
Back
Top