I have a form that contains dataGridView, whose coloumn are set to
dgrv1.Width =dgrv1.Columns.GetColumnsWidth(DataGridViewElementStates.Visible)+20;
I want to make the form to automaticaly follow the width of da开发者_高级运维taGridView...
Also, on maximized, I would like it to grow in height only.
Any sugestions?
Well, you have got a Width value. Set both the MaximumSize and MinimuSize properties of the Form to that value. Maybe with a little margin in between.
Leave the Max/Min Height properties on 0
for default.
Additional:
this gives me a Form that can only be 200 width, but the default '0' for height seems not to work.
private void Form1_Load(object sender, EventArgs e)
{
this.MinimumSize = new Size(200, 400);
this.MaximumSize = new Size(200, 1200);
}
Have you tried using the main form's OnChange event?
private void MainForm_SizeChanged(object sender, EventArgs e)
{
this.Width = ...;
this.Height = ...;
}
精彩评论