I'm noticing some strange behavior when I add a ComboBox
to my Windows Form
:
when I resize the Form
without a ComboBox
, it behaves correctly and the File menu stays where it's supposed to stay even when I drag the right corner as far left as possible. When I add the ComboBox
and I try to do the same thing, then the File menu gets pushed to the left... in my actual application the File menu completely disappears, but it's based on the same problem.
Here is the "normal" resize, where the file menu stays in the right location:
And here is the "abnormal" resize, where the file menu, the group box and the status strip all get pushed to the left:
The only difference between the two forms is the ComboBox
... does anybody have any idea why this may be happening and how can I fix it?
Update
The Left
value/property of the fileMenuStrip
becomes negative and that makes things really ugly, because I have a DataGridView
below the group boxes that is always offset to the right of 0 by a fixed padding (say 50 px). At that point the distance between the Left side of the DataGridView and the Left side of the File menu becomes 105 px, since the File menu is now at -55.
Notice that even when I scroll all the wa开发者_开发百科y to the left, the File menu still stays at -55... so if I have something offset from 0 by 50 (like my GridView), then at this point the difference between them will be 105 pixels.
This looks like this because the scroll area is different between the two forms. This is because you now have a control on the form that accepts Focus. Since the combo box has focus, the scroll region adjusts to keep it visible. Due to this, the File menu appears to move to the left, but is actually in the same location on the form.
Auto scroll is trying to keep the cursor in view when you resize.
You can use the AutoScrollMargin, AutoScrollMinSize, MinimumSize, MinimumSize properties to stop things looking too bad when the form is sized to extremes.
The container controls can also help create a layout that sizes better.
Its not easy creating a layout that works full screen and small, you may even need to completely change the layout when the form gets too small.
It looks like the form auto-scroll is scrolling the combo-box into view where the cursor is because it has the input focus.
精彩评论