views:

57

answers:

3

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:

Normal

And here is the "abnormal" resize, where the file menu, the group box and the status strip all get pushed to the left:

Abnormal

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.

Negative

Notice that even when I scroll all the way 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.

+1  A: 

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.

Adrian
Yah, it's a bit of a pain... and I'm not even trying to do anything fancy, I just want the scroll to turn on and scroll when it needs to. Should I change the focus of the ComboBox?
Lirik
I had a thought, remove the auto-scroll from the form, put a panel on it and set the panel's AutoScroll to true, and set it's Dock to Fill. Then put your stuff on/in the panel. The menu strip should remain outside the panel. This should stop the menu strip moving around with the form.
Adrian
@Adrian, yes! That works! After careful adjustment I got everything to work as I want it... or as close to what I wanted as possible. Thanks for the help!
Lirik
+2  A: 

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.

davisoa
+1  A: 

It looks like the form auto-scroll is scrolling the combo-box into view where the cursor is because it has the input focus.

Andy