F
F
foxlye2019-02-01 20:07:22
C++ / C#
foxlye, 2019-02-01 20:07:22

How to pass variable value to another c# form?

I have 2 forms:
1. Login
2. Menu
In the Login form there is a textbox2 in which the "login" of the user is entered.
There is a lg variable.
string lg = textbox2.Text;
You need to pass the lg variable from the Login form to the Menu form.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
LiptonOlolo, 2019-02-01
@LiptonOlolo

In Login form: In Menu form:

Login login = new Login();
login.ShowDialog();

string log = login.Lg;

J
John_Nash, 2019-02-03
@John_Nash

1) Form is the same object as everything else. If there is a link to it, then all public properties can be read through the dot
2) The second form can be subscribed to the events of the first, but you need to understand well why this is done

I
itgood, 2019-02-04
@itgood

well, you can pass it through the constructor or through the properties

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question