继承 属性 与设置 BindableAttribute

Inheriting a Property vs setting the BindableAttribute

CONTROL class 的 man 属性被 FORM class 继承。但是,根据 MSDN 文档,有些属性(如 LOCATION、TEXT 等)不会被继承。而他们提到的是

The Location property gets or sets the Location property of the Control base class, and sets the Bindable property to true.

这句话是什么意思?继承不是一件轻松简单的事情吗?有人可以请问发生了什么事吗?为什么要这样做?

这是Form.Location属性的实现:

/// <summary>
///  Gets or sets the location of the form.
/// </summary>
[SettingsBindable(true)]
public new Point Location
{
    get => base.Location;
    set => base.Location = value;
}

基本上,它作为 Control.Location 属性 的直通,所以它的行为就好像它大部分是继承的,但它也使 属性 在表单上通过设置更容易绑定,其中控件上的基础 属性 不那么容易绑定。这样做的原因是您通常不会移动控件并希望记住它们在会话中的位置,但对表单这样做是很常见的,因此添加该属性以使其通过设置更容易做到这一点。

要查看结果,请创建一个窗体并向其添加一个控件。 Select控件,打开属性window展开(ApplicationSettings)节点。在那里您将看到列出的 Text 属性。现在对表单本身执行相同操作,您将看到 Location 属性 与 Text 一起列出。如果您进入 (PropertyBinding),那么您仍然可以为控件绑定 Location,但是该属性使表单更容易,因为这样做对于表单来说更为常见。