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

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.

Leave a Comment