Note that there are some explanatory texts on larger screens.

plurals
  1. POSet Statusbar Text on Mouse Hover - Works for controls but not MenuItems
    primarykey
    data
    text
    <p>I devised the following code for displaying a control's Tag property on mouseover. The code works fine for standard controls such as Labels and TextBoxes but I cannot get it to work for my MenuItems (more specifically ToolStripMenuItems). Could y'all please take a look at my code and tell me what I did wrong? Thanks in advance!</p> <pre><code>public void Form1_Load(object sender, EventArgs e) </code></pre> <p><code>{</code></p> <p><code>...</code></p> <p><code>this.addEventsToAllComponents(this);</code></p> <p><code>}</code></p> <pre><code> private void addEventsToAllComponents(Component component) { if (component is MenuItem) { MenuItem menuItem = component as MenuItem; menuItem.Select += new EventHandler(menuItem_Select); } else if (component is Control) { Control ctrl = component as Control; foreach (Control control in ctrl.Controls) { control.MouseEnter += new EventHandler(this.control_MouseEnter); control.MouseLeave += new EventHandler(this.control_MouseLeave); if (control.HasChildren) addEventsToAllComponents(control); } } } private void menuItem_Select(object sender, EventArgs e) { MenuItem menuItem = sender as MenuItem; if (menuItem.Tag.ToString().Length &gt; 0) this.toolStripStatusLabel1.Text = menuItem.Tag.ToString(); } private void control_MouseEnter(object sender, EventArgs e) { Control control = sender as Control; if (control.Tag.ToString().Length &gt; 0) this.toolStripStatusLabel1.Text = control.Tag.ToString(); } private void control_MouseLeave(object sender, EventArgs e) { if (this.toolStripStatusLabel1.Text.ToString().Length &gt; 0) this.toolStripStatusLabel1.Text = ""; } </code></pre>
    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