TableLayoutPanel中列宽在运行时:奇怪的行为或错误 [英] TableLayoutPanel column widths at runtime: strange behavior or bug

查看:284
本文介绍了TableLayoutPanel中列宽在运行时:奇怪的行为或错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个或7列一个TableLayoutPanel。用户可以点击显示/隐藏周末按钮,从5〜7天进行切换。

问题:当你开始用5天,然后preSS的5/7按钮,7列不是均匀分布... 6列要小得多那么剩下的。 奇怪的是,如果你开始使用7天​​,一切看起来OK。当您切换到5,然后回到7,还是一切都很好??

 无效lblSatSunday_Click(对象发件人,EventArgs的)
    {
        !ShowZaterdagZondag = ShowZaterdagZondag;
        AddDisplayControls();
    }

    私人无效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;我++)
        {
            ColumnStyle CS =新ColumnStyle(SizeType.Percent,100 / tblPanel.ColumnCount);
            tblPanel.ColumnStyles.Add(CS);

            //添加手风琴
            手风琴A =新的手风琴();
            //删除code阅读
            tblPanel.Controls.Add(一);
        }
        tblPanel.ResumeLayout();
    }
 

解决方案

在for循环添加这行code:

  tblPanel.ColumnStyles.Clear();
 

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();
    }

解决方案

Add this line of code before the for loop:

 tblPanel.ColumnStyles.Clear();

这篇关于TableLayoutPanel中列宽在运行时:奇怪的行为或错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆