C# – Resize TabPage,Controls and Form

cdatagridviewresizetabpagewinforms

I want to resize the tabpage, its internal Control which is dataGridview and Finally resize the form in which theay are contained.

I have implemented the Drag functionality of tabpages.Now i want to increase tabPage Size based on the DatagridviewRows.

if(dgv.Rows.count<=15)
  Resize tabPage to show  data to show 'n' No. Of Rows
else if(dgv.Rows.count>15)
  Resize to show 15 Rows data then Scroll bar.

I have tried setting the Dock and Anchor property of gridview.But only the tabpage is filled.I want the tabpage to be resized with increasing No of rows and Finally resize Form in which it is contained.

Kindly help.

Best Answer

I think the better way is to change size of others controls accourding to your form resize.

    private void Form1_Resize(object sender, EventArgs e) //form resize event
    {
      grdView1.SetBounds(Left,Top, this.Width-10,this.Height-10);

      grdView1.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
      grdView1.Columns[0].FillWeight = 45;

      //same for other columns according to your requirments.

    }

and also set the size of tabpage accourding to Form size.

Related Topic