3
votes

I have a Windows Form with a default size of 1100x400, and I have a DataGridView control on it anchored to Top, Left, Bottom, Right.

Resizing the form on a screen with resolution higher than 1100x400 works fine, and the anchoring works well, resizing the DataGridView control as expected.

When I launch the form on a screen with resolution 800x600, the form is cut off, and made to fit the 800x600. The DataGridView is cut off, and cannot be seen entirely - it bleeds off the form to the right, so it's not respecting the right anchor. Resizing the form in this situation doesn't respect the anchoring settings for some reason: the DataGridView control does not resize when the form is resized.

Is there a way programmatically (on a resize event or something) to force the child DataGridView control to anchor to the sides of the form?

I've already tried calling a PerformLayout and Refresh in the Form's resize event but it's rather redundant, isn't it?

1
>>I've already tried calling a PerformLayout and Refresh in the Form's resize event but it's rather redundant, isn't it?<< -- Did that work?Robert Harvey
Seems like a silly question, but is there anything set for the minimum width of the cotrol? (I'm not at my dev box so I can't check to see if that's something you can do to a DataGridView or not, so just ignore me if I'm thinking of a different UI framework.)Al Crowley

1 Answers

0
votes

I would recommend you to play with MinimumSize/MaximumSize of the form and controls

We usually set MinimumSize for the form and controls to the value, when we can see at least small part of each control. There is no use to allow resizing a form to the size, when you cannot do any usefull work with the controls on it

As for MaximumSize for the form - I'll recommend you to try setting this value on Form_Load to be less or equal current screen resolution or current working area (which is the screen area without taskbars, docked windows, etc.)

see
    Screen.PrimaryScreen.Bounds
    Screen.PrimaryScreen.WorkingArea