Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few problems with your code.</p> <p>1st. The Items of a MenuStrip are not children of the Item, so HasChildren will return false. Instead, they are in the Items collection of the MenuStrip. You need to handle a MenuStrip occurrence specially. Add the following code in your AddEvents... method below:</p> <pre><code>(snip...) // old code if (control.HasChildren) AddEventsToAllControls(control); //add new code below if (control is MenuStrip) { MenuStrip ms = control as MenuStrip; AddEventsToAllToolStripMenuitems(ms.Items); } </code></pre> <p>And add the new method as follows:</p> <pre><code>private void AddEventsToAllToolStripMenuitems (ToolStripItemCollection items) { foreach (ToolStripItem tsi in items) { tsi.MouseEnter += new EventHandler(this.control_MouseEnter); tsi.MouseLeave += new EventHandler(this.control_MouseLeave); if (tsi is ToolStripMenuItem) { ToolStripMenuItem mi = tsi as ToolStripMenuItem; AddEventsToAllToolStripMenuitems(mi.DropDownItems); } } } </code></pre> <p>2nd. ToolStripItem doesn't derive from Control, so in MouseEnter the <em>sender as Control</em> statement will fail (control will be null). Do something like this:</p> <pre><code>Control control = sender as Control; if (control != null &amp;&amp; control.Tag != null &amp;&amp; control.Tag.ToString().Length &gt; 0) this.toolStripStatusLabel1.Text = control.Tag.ToString(); ToolStripItem tsi = sender as ToolStripItem; if (tsi != null &amp;&amp; tsi.Tag != null &amp;&amp; tsi.Tag.ToString().Length &gt; 0) this.toolStripStatusLabel1.Text = tsi.Tag.ToString(); </code></pre> <p>(I also added some null checks)</p> <p>This should get you going.</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.
 

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