c# Accessing WinForm control properties from another class

后端 未结 4 609
难免孤独
难免孤独 2021-01-22 02:58

How does one access WinForm controls such as ProgressBar properties from another class?

Please see my code below. I know this might not be the best option

4条回答
  •  清酒与你
    2021-01-22 03:28

    You do not want your business logic (your class) interacting with your UI (your form). The business logic should be agnostic of the presentation layer.

    If you want the form to respond to things that happen inside the class, you could consider exposing an Event inside the class that the form could subscribe to, much like it would subscribe to a button's click event. The class instance could fire off the event completely unaware of who might be listening, and any subscribers would be notified.

提交回复
热议问题