VB.NET 视觉继承:朋友 VS 受保护

发布于 2024-09-06 08:32:19 字数 255 浏览 5 评论 0原文

为什么如果使用访问修饰符 Friend 声明某些组件/控件,而使用 Protected 声明它们,则它们不会在子窗体中直观地继承。

例如,我的父窗体中有一个最初为“Friend”的 DataSet 对象(我将其拖放到窗体中,因此它在设计器视图中显示为控件),但我注意到我的子窗体没有按预期继承控制权。一旦我将其更改为“受保护”,它就会按预期显示在我的儿童表单中。

我知道 Protected 允许子窗体修改继承的控件,但这到底是如何与我上面描述的问题联系起来的呢?

Why is it that some components/controls will not be inherited visually in a child form if they are declared with the access modifier Friend vs when they are declared with Protected.

For example, I've got a DataSet object in my Parent Form that was initially "Friend" (I drag and dropped it to the form, so it was shown as a control in the designer view), but I noticed that my Child Form did not inherit the control as expected. Once I changed it to "Protected", it showed up in my Child form as expected.

I am aware that Protected allows the Child Form to modify the inherited control, but how exactly does this tie in to the issue I described above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2024-09-13 08:32:19

它取决于声明基本形式的程序集。如果这是另一个程序集,而不是派生形式所在的程序集,那么 Friend 就无法工作。声明为 Friend 的成员只能在同一程序集中访问。

protected 是这里正确的访问修饰符。它确保派生形式在哪个程序集中声明并不重要。并确保只有派生表单类可以访问数据集。

It depends on the assembly in which the base form is declared. If that's another assembly than the one in which the derived form lives then Friend cannot work. Members declared Friend are only accessible inside the same assembly.

Protected is the proper access modifier here. It ensures that it doesn't matter in what assembly the derived form is declared. And ensures that only derived form classes can access the dataset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文