A
A
andrejfomenko2020-04-17 18:08:31
C++ / C#
andrejfomenko, 2020-04-17 18:08:31

How to do correct click handling in c#?

There is form 1, it creates form 2, in form 2 there are two textboxes and a button, you need to make sure that by clicking this button, the data from textbox1 is written to variable 1, and textbox2 to variable 2 and the form is closed. Form 2 runs in a separate thread. How to implement it correctly? specifically the handler button1.click += new EventHandler(method);
but in method() it is not possible to take data from form2 and close it too.

private void zapusk_form2(object sender, EvantArgs e)
{  
Thread tr = new Thread(go)
tr.Start();
}
public void go()
{
            Thread autent = new Thread(aut);
            autent.Start();
           .......
}
public void aut()
        {            
            Form2 auts = new Form2();
            auts.Show();
            auts.button1.Click += new EventHandler(metod);
        }
        public string login;
        public string pass;
        private void metod(object sender, EventArgs e)
        {
            login = auts.textBox1.Text;
            pass = auts.textBox2.Text;
            auts.Hide();

        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-04-17
@andrejfomenko

Keep the project.
Your login is in the correct key. Notice the docking controls in the second form.
Well, most importantly, select a global object in which the application logic will be. And on forms only assign variables. In general, as little code as possible in the forms.
https://yadi.sk/d/Usu-r-Bo1955fQ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question