What's the simplest .NET equivalent of a VB6 control array?

后端 未结 9 1726
时光取名叫无心
时光取名叫无心 2020-12-11 03:42

Maybe I just don\'t know .NET well enough yet, but I have yet to see a satisfactory way to implement this simple VB6 code easily in .NET (assume this code is on a form with

9条回答
  •  渐次进展
    2020-12-11 03:51

    The two main benefits of control arrays in VB6 were: (1) They provided a way for you to iterate through a collection of controls (2) They allowed you to share events between controls

    (1) can be accomplished in .Net using an array of controls (2) can be accomplished by having one event handle multiple controls (the syntax is a little different because you use the sender argument instead of myArray(index)).

    One nice thing about .Net is that these features are decoupled. So for instance you can have controls that share events even if they aren't part of an array and have different names and even a different type. And you can iterate through a collection of controls even if they have totally different events.

提交回复
热议问题