Windows application

How to transfer variables between Winforms? Customer ID Example

thanks

0
source share
4 answers

You must declare public property in the form you want to transfer. Then, creating a new form, this is a simple assignment:

FROM#: MyOtherInstantiatedForm.CustomerID = CurrentCustomerID;

Do you need to pass CustomerID to multiple forms? What about other customer information? If you provide more details, we can probably offer you a better solution.

+2
source

The most important thing to note here is that form is nothing but a C # class. If you think of a form in these terms, the answer will probably jump out by itself.

, , . -, , . , , .

CoolForm myForm = new CoolForm();

myForm.MyProp = "Hello World";
myForm.ShowDialog();

- . , , . , , .

CoolForm myForm = new CoolForm("Hello World");

myForm.ShowDialog();

, ...

+5

CustomerID :

frmTwo.CustomerId = frmOne.CustomerId
+2

, .

Form2 frm = new Form2(customerId);

. , , .

+2

Source: https://habr.com/ru/post/1722899/


All Articles