.net框架如何在类中嵌套表单。 (vb.net)
如果我使用反射器查看框架中的某些类,我可以看到表单和用户控件被设为私有并嵌套到父类中。
例如,我有一个控件,它使用特定于该控件的弹出窗体。 目前,我使弹出表单朋友可以访问。 如果我想以框架方式完成它,我会将其设为私有并将其嵌套到控制类中。 但是,如果我这样做,我将无法再使用 ide 来设计表单,并且在尝试编译时会出现错误。 所以,我有两个问题:
(1)微软是否在最后一刻采取措施将所有内容嵌套为私有?
(2) 他们的方式是首选方式还是我应该坚持使用我的朋友访问器?
If I look at some classes in the framework, using reflector, I can see that forms and user controls are made private and nested into a parent class.
For instance, I have a control which makes use of pop-up form that is specific to that control.
At the moment, I make the pop-up form friend accessible.
If I wanted to do it the framework way, I'd make it private and nest it into the control class.
If I do this, however, I can no longer use the ide to design the form and I get errors when I try to compile.
So, I have 2 questions:
(1) Do Microsoft do something at the last minute to nest all things private?
(2) Is their way the preferred way or should I stick to my friend accessors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嵌套形式更好,因为它强制执行正确的封装,并且意味着最终的控件将最终出现在一个漂亮整洁的包中以供分发。如果你不关心这些,就继续按照你的方式去做。但是,如果您至少想尝试嵌套该类,则可以执行以下操作:
*.designer.vb< 迁移代码第一个表单的 /code> 或
*.designer.cs
到第二个表单的构造函数。它主要只是一个大的复制/粘贴。The nested form is better, because it enforces correct encapsulation and means the final control will end up in one nice neat package for distribution. If neither of those are a concern for you keep doing it your way. But if you want to at least try nesting the class, you can do something like this:
*.designer.vb
or*.designer.cs
for your first form to the constructor for your 2nd form. It'll mostly be just a big copy/paste.