Send values from one form to another form

后端 未结 19 2518
眼角桃花
眼角桃花 2020-11-21 11:45

I want to pass values between two Forms (c#). How can I do it?

I have two forms: Form1 and Form2.

Form1 contains one button. When I click on that button, Fo

19条回答
  •  不知归路
    2020-11-21 12:16

    After a series of struggle for passing the data from one form to another i finally found a stable answer. It works like charm.

    All you need to do is declare a variable as public static datatype 'variableName' in one form and assign the value to this variable which you want to pass to another form and call this variable in another form using directly the form name (Don't create object of this form as static variables can be accessed directly) and access this variable value.

    Example of such is,

    Form1

    public static int quantity;
    quantity=TextBox1.text; \\Value which you want to pass
    

    Form2

    TextBox2.Text=Form1.quantity;\\ Data will be placed in TextBox2
    

提交回复
热议问题