Safest way to pass data between forms in c# winforms

前端 未结 2 642
栀梦
栀梦 2021-01-24 02:06

I\'m trying to remember a lesson I was taught briefly in school about safely passing data between winforms.

My instructor called it pipelining, though I\'m not

2条回答
  •  星月不相逢
    2021-01-24 03:00

    I usually declare my variable in program.cs in your situation, and reach it from anywhere as Program.xxx. but you need a non public way of reaching a variable...

    Ahhaaa, another way is as following. when you create a form from another form. Write an overloaded contructor for second form, and pass parameters to that contructor. like:

    Form2 frm = new Form2(myParameter);
    

提交回复
热议问题