How to access form objects from another cs file in C#

前端 未结 5 682
广开言路
广开言路 2020-12-29 15:15

In the form.cs file I have two buttons,a memo and a timer.My question is: How do I access the timer or the memo from another cs file?

I\'ve tried to make the objects

5条回答
  •  太阳男子
    2020-12-29 15:28

    I worry whenever I hear someone talking about "another .cs file" or "another .vb file". It often (though not always) indicates a lack of understanding of programming, at least of OO programming. What's in the files? One class? Two?

    You're not trying to access these things from another file, you're trying to access them from a method of a class, or possibly of a module in VB.

    The answer to your question will depend on the nature of the class and method from which you're trying to access these things, and the reason why you want to access them.

    Once you edit your question to include this information, the answers you receive will probably show you that you shouldn't be accessing these private pieces of the form in classes other than the form class itself.

提交回复
热议问题