Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have not actually overriden the <code>TabStop</code> property, because <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.tabstop.aspx" rel="nofollow">it is not virtual</a>.</p> <p><em>What you have done is "hidden" it by creating another property with the same name</em>. Therefore, a different property setter is executed when you try to set <code>Control.TabStop</code> here:</p> <pre><code>// The static type of c is Control! if (((ClassA)c).Properties.ReadOnly) c.TabStop = false; </code></pre> <p>And when you set it here:</p> <pre><code>// The static type is now ClassA ((ClassA)c).TabStop = false; </code></pre> <p>When you refer to the property, the compiler resolves the name using <strong>static</strong> binding because it is not virtual. For that reason if you do not cast the object to something more derived than <code>Control</code>, you will not see your own code run.</p> <p><strong>Update:</strong> This still leaves some open questions:</p> <ol> <li>Why does the compiler bind to <code>MyControl.TabStop</code> if the static type of the variable is <code>ClassA</code>? Shouldn't it still bind to <code>Control.TabStop</code>?</li> <li>Why does the compiler let you write <code>Public Overrides Property TabStop As Boolean</code> if <code>Control.TabStop</code> is not virtual?</li> </ol> <p>We know that there has to be <em>some</em> class in the hierarchy between <code>Control</code> and <code>MyControl</code> with a virtual <code>TabStop</code> property (otherwise <code>Overrides</code> on <code>MyControl.TabStop</code> would be a compiler error). We also know that <code>ClassA.TabStop</code> ends up binding to <code>MyControl.TabStop</code>. Assuming that there is no other class in the hierarchy between <code>Control</code> and <code>ClassA</code>, there is only one logical explanation: class <code>ClassA</code> defines a virtual <code>TabStop</code> property that <code>Shadows</code> <code>Control.TabStop</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload