Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
3.00/5 (3 votes)
i am making a windows application then it open there will be a button when i press the button a window will open and there will be a button and a textbox... when i press the button number 2 window will close and the text in the textbox (from window 2) will be send to a label in the first window
Posted
Updated 10-May-11 1:45am
v3
Comments
yesotaso 10-May-11 6:59am    
Is it "windows" or "processes" are you talking about? Do you have 2 seperate window created 1 application, or 2 window created by 2 different application? I ask because title implies so.
[Edit] typo [/Edit]
Sergey Alexandrovich Kryukov 10-May-11 23:57pm    
Where are two difference applications (processes)? You only tell about two windows.
--SA
jackhold 11-May-11 5:26am    
its 1 application but 2 windows
when you open the program there will pop-up a window in that window there will be label1 and button1 when you push the button a new window2 will open. in that window2 there will be button2 and textbox1 now when you click button2 the window2 will close and label1 will change to the text that you had typed in textbox1
Sergey Alexandrovich Kryukov 11-May-11 15:43pm    
Thank you for clarification. You get well-tested solution from me, please see.
--SA

 
Share this answer
 
Comments
Tarun.K.S 10-May-11 4:02am    
Good link. 5+
charles henington 10-May-11 6:39am    
A 4 from me although the poster wanted to send information to a previous form which the link explains sending to a new Form but the basics lie here in this link. Great solution but please check out my solution.
The best, neat and successful method of collaboration is based on implementing some interface by the Form or Window class.

Please see my past answer and discussion here:
How to copy all the items between listboxes in two forms[^].

—SA
 
Share this answer
 
i found out how to do it by my self....
 
Share this answer
 
Here is the Parent Form, You will notice that our Color bgColor is an internal method as well as our FormHook. with the FormHook we will be able to call any internal or public method in this Form from any Form in our project.

C#
public partial class Form1 : Form
    {
        internal static Form1 FormHook;    
      
        internal Color bgColor
        {
            get { return this.BackColor; }
            set {this.BackColor = value;}
        }

        public Form1()
        {
            InitializeComponent();
            FormHook = this;
            Form2 form = new Form2();
            form.Show();
        }
    }


To call this method you could just call as

C#
Form1.FormHook.bgColor = Color.Black;


If You want to use dynamic method it could be done as such

C#
public partial class Form1 : Form
    {
        internal static dynamic FormHook;    
      
        internal Color bgColor
        {
            get { return this.BackColor; }
            set {this.BackColor = value;}
        }

        public Form1()
        {
            InitializeComponent();
            FormHook = this;
            Form2 form = new Form2();
            form.Show();
        }
    }


Would still be called the same way Form1.FormHook.bgColor = Color.Black;
 
Share this answer
 
v2
Comments
ambarishtv 10-May-11 6:48am    
My 5 :)
jackhold 10-May-11 9:13am    
What if i wanner do this from form2 to form1?
charles henington 14-May-11 11:35am    
Not sure if I understand your question. but if you want to use a call to change objects in form1 from form2 use the method above but if you want to change an object in form2 from another form put internal static Form2 FormHook in form2 and call form2 from other forms

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900