Note that there are some explanatory texts on larger screens.

plurals
  1. POToolStripMenuItem.Bounds returning different values with no control move
    primarykey
    data
    text
    <p>I have a program with a MenuStrip at the top, it currently has 4 items. What I'm essentially trying to do is make sure that all 4 of these menu items are visible if the user shrinks the width.</p> <p>My initial attempt was to get the total number of items on the MenuStrip by simply grabbing the item collection then grab the bounds of the last item on the strip. After retrieving the bounds variable, I then do a quick calculation of the bounds.x + bounds.width to make sure that the form.width is not less than that, if so, it resizes. All of this takes place within the ResizeEnd event for the form.</p> <pre><code>private void F_Main_ResizeEnd(object sender, EventArgs e) { ToolStripItemCollection t_col = menuStrip1.Items; int _howMany = t_col.Count; var mi_bounds = t_col[_howMany - 1].Bounds; if (this.Width &lt; (mi_bounds.X + mi_bounds.Width)) this.Width = (mi_bounds.X + mi_bounds.Width); } </code></pre> <p>Now, the code seems to work, most of the time. I found that if I shrunk the form so that either the 2nd or 3rd item dissapeared, it resized too thin and left the 4th menu invisible. At that point, interestingly enough, if I simply clicked on the right edge of the form - as if I would be resizing but not moving the form, it would then recover to the correct width and display all 4 menu items.</p> <p>What I found was that the bounds property of the toolstripmenuitem changed and was value {a} when I started resizing with all 4 showing and value {b} when only 3 were showing.</p> <p>I'm now trying to figure out a more reliable way to make sure that all my menu items are visible and the form resize to the proper width.</p> <p>Sorry if this doesn't explain it properly as this is a <em>weird</em> problem for me.</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. 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