tags:

views:

373

answers:

1

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

Resizing the form on a screen with resolution higher than 1100 x 400 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 800 x 600. 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?

A: 

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
Bogdan_Ch