运行时的 TableLayoutPanel 列宽度:奇怪的行为或错误
我有一个包含 5 列或 7 列的 tableLayoutPanel。用户可以点击“显示/隐藏周末”按钮从5天到7天切换。
问题:当您从 5 天开始,然后按 5/7 按钮时,7 列间隔不均匀......第 6 列比其余列小得多。 奇怪的是,如果你从 7 天开始,一切看起来都很好。当你切换到 5 然后再回到 7 时,仍然一切正常?
void lblSatSunday_Click(object sender, EventArgs e)
{
ShowZaterdagZondag = !ShowZaterdagZondag;
AddDisplayControls();
}
private void AddDisplayControls()
{
tblPanel.SuspendLayout();
tblPanel.Controls.Clear();
tblPanel.ColumnCount = ShowZaterdagZondag ? 7 : 5; // <<<-------
tblPanel.RowCount = 1;
tblPanel.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;//.AddColumns;
for (int i = 0; i < tblPanel.ColumnCount; i++)
{
ColumnStyle cs = new ColumnStyle(SizeType.Percent, 100 / tblPanel.ColumnCount);
tblPanel.ColumnStyles.Add(cs);
//Add accordeon
Accordeon a = new Accordeon();
//Removed code for reading
tblPanel.Controls.Add(a);
}
tblPanel.ResumeLayout();
}
I have a tableLayoutPanel with either 5 or 7 columns. Users can click "show/hide weekend" button to switch from 5 to 7 days.
The problem : When you start with 5 days, then press the 5/7 button, the 7 columns are NOT spaced evenly ... column 6 is much smaller then the rest.
The strange thing is that if you start with 7 days, all looks ok. When you switch to 5 and then back to 7, still all is fine ??
void lblSatSunday_Click(object sender, EventArgs e)
{
ShowZaterdagZondag = !ShowZaterdagZondag;
AddDisplayControls();
}
private void AddDisplayControls()
{
tblPanel.SuspendLayout();
tblPanel.Controls.Clear();
tblPanel.ColumnCount = ShowZaterdagZondag ? 7 : 5; // <<<-------
tblPanel.RowCount = 1;
tblPanel.GrowStyle = TableLayoutPanelGrowStyle.FixedSize;//.AddColumns;
for (int i = 0; i < tblPanel.ColumnCount; i++)
{
ColumnStyle cs = new ColumnStyle(SizeType.Percent, 100 / tblPanel.ColumnCount);
tblPanel.ColumnStyles.Add(cs);
//Add accordeon
Accordeon a = new Accordeon();
//Removed code for reading
tblPanel.Controls.Add(a);
}
tblPanel.ResumeLayout();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在for循环之前添加这行代码:
Add this line of code before the for loop: