繁体   English   中英

如何在datagridview中调整行的大小,以便它们填充整个控件并全部具有相同的高度

[英]How to resize rows in a datagridview so that they fill the entire control and all have the same height

我目前正在使用事件管理应用程序。

到目前为止,我已经使用DataGridView控件显示每月日历:

在此处输入图片说明

但是表行的大小不正确。

我想实现以下照片中的效果:

在此处输入图片说明

请注意,如果调整网格大小,六行的高度是相同的,并且比例将保持不变。

我试图通过DataGridView.AutoResizeRows实现这一点。 没用 有解决方案吗?

DataGridViewScrollBars属性设置为None并使用此代码设置行的大小:

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    row.Height = (dataGridView1.ClientRectangle.Height - dataGridView1.ColumnHeadersHeight) / dataGridView1.Rows.Count;
}

还使用此代码来处理大小调整:

private void dataGridView1_SizeChanged(object sender, EventArgs e)
{
    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        row.Height = (dataGridView1.ClientRectangle.Height - dataGridView1.ColumnHeadersHeight) / dataGridView1.Rows.Count;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM