user2998513
user2998513

Reputation: 23

How can I make a control take 80% of the parent's height

I know you can dock an item to cover the bottom, top, left, right, or all of the form. But I want to have a datagridview cover 80% of the height of the forum and all of the width and cannot figure out how to do that.

Upvotes: 1

Views: 693

Answers (2)

Setsu
Setsu

Reputation: 1228

You can use the TableLayoutPanel (MSDN) to accomplish this, and can be done entirely in the designer.

Add a TableLayoutPanel and have it fill you entire form. Then, create 2 rows in the panel and give the first row a percentage value of 80% for height (Your options are percentage, pixels, and auto-fill). Finally, move your DataGridView into the first row and dock it to the entire row.

Upvotes: 4

Reddog
Reddog

Reputation: 15579

You can use the docking (e.g. Top or Bottom) to setup the width part of your problem, however, to synchronize the height you'll need to programmatically calculate it (and keep it synced).

There's an example here that sets the width so that idea will apply: https://stackoverflow.com/a/18384344/33969. You'll want to call that function on form load, but also as an event handler for the Form.Resize event.

Upvotes: 1

Related Questions