give same property to all textbox controls
<p>how to give same property to all textboxes present in the same form.</p>

<pre><code>      foreach (var textbox in this.Controls.OfType&lt;TextBox&gt;())
        {
            textbox.ContextMenu = new ContextMenu();
        }
</code></pre>

<p>The above code works only if the textboxes are not in nested format.</p>

<p>In my project I have multiple tabpages in tabcontrol. so i cant implement the above code. but i can implement the below code:</p>

<pre><code>      foreach (TextBox textbox in this.Controls.OfType&lt;TabControl&gt;().SelectMany(tc =&gt; tc.Controls.OfType&lt;TabPage&gt;().SelectMany(page =&gt; page.Controls.OfType&lt;TextBox&gt;())))
        {
            textbox.ContextMenu = new ContextMenu();
        }
        foreach (var textbox in this.tabCarInsurance.Controls.OfType&lt;TextBox&gt;())
        {
            textbox.ContextMenu = new ContextMenu();
        }
        foreach (var textbox in this.tabHomeLoans.Controls.OfType&lt;TextBox&gt;())
        {
            textbox.ContextMenu = new ContextMenu();
        }
        foreach (var textbox in this.tabRetirement.Controls.OfType&lt;TextBox&gt;())
        {
            textbox.ContextMenu = new ContextMenu();
        }
</code></pre>

<p>Here I am implementing for each tabControl. which still i dont like (because I have more tab pages to take care of). Is there anyway to reduce the above code.</p>

<p>I tried the below code: (<em>not working</em>)</p>

<pre><code>       foreach (var textbox in this.Controls.OfType&lt;TabControl&gt;().OfType&lt;TextBox&gt;())
        {
            textbox.ContextMenu = new ContextMenu();
        }
</code></pre>

<p>I got the above code knowledge from my <a href="http://stackoverflow.com/q/12894451/1577396">previous question</a>.</p>

<p>Please Help
<br>Thanks in Advance.</p>
