Click here to Skip to main content
15,907,906 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am working with two forms with two buttons and one text box on each form1 and one text box on form2.i want on click of button 1 in form 1 form 2 should appear and on click of button 2 color of both text box should change
Posted
Comments
Richard MacCutchan 15-Oct-14 5:02am    
OK, so you have told us what you want. Perhaps you could explain what you have tried and where you need help.
Sinisa Hajnal 15-Oct-14 5:13am    
Sounds like homework. What have you tried?
BillWoodruff 15-Oct-14 5:24am    
Why are you re-posting the same question you asked a few hours ago ?
Member 11154071 15-Oct-14 5:27am    
got it!!thanx

See, for instance, this Stack Overflow question: "Communicate between two windows forms in C#"[^].
 
Share this answer
 
Hope it might help you
Passing Data between Windows Forms[^]
 
Share this answer
 
Hi there, I think I understood your problem. So you not only want to open a new form, but you want to change the backcolor of the textbox on the 2nd form. So it means you want to call the 2nd form event within the first form. You can do it as below.

C#
//-----------------------------Form1----------------
 //Create form1 and add 1 textbox and 2 buttons on it
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Form2 frm2 = new Form2();
        
        private void button1_Click(object sender, EventArgs e)
        {
           frm2.Show();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.Red;
            frm2.TextboxBackColor = Color.Red;
            frm2.button1_Click(sender, e);
        }
    }


//-----------------------------Form2----------------

//Create form2 and add one textbox and a button on it
    public partial class Form2 : Form
    {
        //Property to get the textbox back color from form1
        public Color TextboxBackColor { get; set; }
        public Form2()
        {
            InitializeComponent();
            //textBox1.BackColor = TextboxBackColor;
        }

        internal void button1_Click(object sender, EventArgs e)
        {
            textBox1.BackColor = TextboxBackColor;
        }
    }
 
Share this answer
 
v3

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