How to pass values between forms in c# windows application?

后端 未结 4 1432
渐次进展
渐次进展 2020-11-27 08:18

I have two forms A and B. Form A is the default start up form of the application. I do some stuffs in Form A and i then i want to run my Form B parallel and then pass a para

4条回答
  •  有刺的猬
    2020-11-27 08:51

    Ian has given some example code, but I'd like to make a broader point:

    UI classes are just classes.

    How would you pass a value from one object to another object if they weren't part of the user interface? You'd have a reference from one to the other, and call a method or set a property. The same exact thing holds for user interface objects.

    I mention this because it's something that comes up a lot. Whenever you ask yourself: "How do I do X with forms?" try asking yourself the same question but with plain old classes. Often the answer will be exactly the same.

    Of course there are some differences for user interface classes - particularly with threading - but for an awful lot of cases, it really helps if you just think of them as normal classes.

提交回复
热议问题