[英]Resize TabPage,Controls and Form
我想调整标签页的大小,它的内部控件是 dataGridview,最后调整包含它们的表单的大小。
我已经实现了 tabpages 的拖动功能。现在我想根据 DatagridviewRows 增加 tabPage 大小。
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.
我已经尝试设置 gridview 的 Dock 和 Anchor 属性。但只填充了标签页。我希望标签页随着行数的增加而调整大小,并最终调整包含它的表单的大小。
请帮忙。
我认为更好的方法是根据您的表单调整大小更改其他控件的大小。
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.
}
并根据表单大小设置标签页的大小。
我使用了下面的代码并且它起作用了。 我将 datagridview 保留在 splitcontainer.Made 的 Splitcontainer 的停靠属性中以填充并将第二个面板保持为固定面板。根据行数和面板高度计算高度并更新表单高度。这样它就起作用了。
int height = this.Height;
CalculateFormHeight(ref height);
this.Size = new Size(this.Width, height);
private void CalculateFormHeight(ref int height)
{
if (dataGridViewToDisplay != null && dataGridViewToDisplay.Rows != null)
{
if (dataGridViewToDisplay.Rows.Count >= 15)
{
height = dataGridViewToDisplay.Rows[0].Height * 18 + splitContainer1.Panel2.Height;
}
else if (dataGridViewToDisplay.Rows.Count < 15)
{
height = dataGridViewToDisplay.Rows[0].Height * (dataGridViewToDisplay.Rows.Count + 3) + splitContainer1.Panel2.Height;
}
}
}
要做到这一点没有太大问题,您必须从选项卡中删除表单,然后重新放置
private void frmMaster_Resize(object sender, EventArgs e)
{
foreach (TabPage tab in tabWindows.TabPages)
{
foreach (Control con in tab.Controls)
{
if (con is Form)
{
this.Controls.Add(con);
// Thread.Sleep(20);
con.Size = (new Size(tab.Width, tab.Height));
tab.Controls.Add(con);
//con.Width = tab.Width;
//con.Height= tab.Height;
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.