Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自动滚动tablelayoutpanel中的图形故障_C#_Autoscroll_Tablelayoutpanel - Fatal编程技术网

C# 自动滚动tablelayoutpanel中的图形故障

C# 自动滚动tablelayoutpanel中的图形故障,c#,autoscroll,tablelayoutpanel,C#,Autoscroll,Tablelayoutpanel,我有一个WinForms表单,其中包含一个动态生成的TableLayoutPanel。在运行时,我添加或删除行,所以我设置了最大大小并将其设置为autoscroll。所有行和列都是自动调整大小的,我为垂直滚动条添加了填充,这样它就不会与单元格重叠(从而强制创建水平滚动条,使用(在表单创建时): 当没有足够的数据来强制自动滚动时,情况如下所示: 问题是,当它添加autoscroll时,会引入这种奇怪的图形故障: 问题是对勾图像下方右侧和对勾上方边框上的白线。我想这一定与滚动条外观设置有关,但我

我有一个WinForms表单,其中包含一个动态生成的
TableLayoutPanel
。在运行时,我添加或删除行,所以我设置了最大大小并将其设置为autoscroll。所有行和列都是自动调整大小的,我为垂直滚动条添加了填充,这样它就不会与单元格重叠(从而强制创建水平滚动条,使用(在表单创建时):

当没有足够的数据来强制自动滚动时,情况如下所示:

问题是,当它添加autoscroll时,会引入这种奇怪的图形故障:

问题是对勾图像下方右侧和对勾上方边框上的白线。我想这一定与滚动条外观设置有关,但我不太确定是什么。有什么想法吗

编辑:为
表格布局面板添加代码

// 
// tableLayoutPanel_dataLogs
// 
this.tableLayoutPanel_dataLogs.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
| System.Windows.Forms.AnchorStyles.Left) 
| System.Windows.Forms.AnchorStyles.Right)));
this.tableLayoutPanel_dataLogs.AutoSize = true;
this.tableLayoutPanel_dataLogs.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.tableLayoutPanel_dataLogs.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.InsetDouble;
this.tableLayoutPanel_dataLogs.ColumnCount = 7;
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
this.tableLayoutPanel_dataLogs.Controls.Add(this.checkBox_getAllDataLogs, 0, 0);
this.tableLayoutPanel_dataLogs.Controls.Add(this.label1, 1, 0);
this.tableLayoutPanel_dataLogs.Controls.Add(this.label2, 3, 0);
this.tableLayoutPanel_dataLogs.Controls.Add(this.label3, 5, 0);
this.tableLayoutPanel_dataLogs.Controls.Add(this.label5, 4, 0);
this.tableLayoutPanel_dataLogs.Controls.Add(this.label4, 2, 0);
this.tableLayoutPanel_dataLogs.Controls.Add(this.pictureBox1, 6, 0);
this.tableLayoutPanel_dataLogs.Location = new System.Drawing.Point(6, 445);
this.tableLayoutPanel_dataLogs.MaximumSize = new System.Drawing.Size(600, 144);
this.tableLayoutPanel_dataLogs.MinimumSize = new System.Drawing.Size(400, 56);
this.tableLayoutPanel_dataLogs.Name = "tableLayoutPanel_dataLogs";
this.tableLayoutPanel_dataLogs.Padding = new System.Windows.Forms.Padding(0, 0, System.Windows.Forms.SystemInformation.VerticalScrollBarWidth, 0);
this.tableLayoutPanel_dataLogs.RowCount = 1;
this.tableLayoutPanel_dataLogs.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel_dataLogs.Size = new System.Drawing.Size(420, 56);
this.tableLayoutPanel_dataLogs.TabIndex = 65;
this.tableLayoutPanel_dataLogs.Visible = false;
下面是添加行的代码:

tableLayoutPanel_dataLogs.Visible = false;

tableLayoutPanel_dataLogs.SuspendLayout();

for (int i = 0; i < logCount; i++)
{
    //code that generates the data to populated not shown
    //...
    //created currentSerial, currentDateTime, currentEntriesCount

    tableLayoutPanel_dataLogs.RowCount++;
    tableLayoutPanel_dataLogs.RowStyles.Add(new RowStyle(SizeType.AutoSize));
    string row = (tableLayoutPanel_dataLogs.RowCount - 1).ToString("D2");
    string cbName = ControlNames.checkBoxSelectedName + row;
    tableLayoutPanel_dataLogs.Controls.Add(new CheckBox { Name = cbName, Text = String.Empty, Anchor = AnchorStyles.None, AutoSize = true }, 0, tableLayoutPanel_dataLogs.RowCount - 1);
    CheckBox cb = this.Controls.Find(cbName, true).First() as CheckBox;
    checkBoxes.Add(cb.Name,cb);
    cb.CheckedChanged += new System.EventHandler(this.checkBox_getAnyDataLog_CheckedChanged);

    tableLayoutPanel_dataLogs.Controls.Add(new Label() { Name = ControlNames.labelNumberName + row, Text = (tableLayoutPanel_dataLogs.RowCount - 1).ToString(), Anchor = AnchorStyles.None, Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), AutoSize = true }, 1, tableLayoutPanel_dataLogs.RowCount - 1);
    tableLayoutPanel_dataLogs.Controls.Add(new Label() { Name = ControlNames.labelSerialName + row, Text = currentSerial, Anchor = AnchorStyles.None, Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), AutoSize = true }, 2, tableLayoutPanel_dataLogs.RowCount - 1);
    tableLayoutPanel_dataLogs.Controls.Add(new Label() { Name = ControlNames.labelDateTimeName + row, Text = currentDateTime.ToString("MM/dd/yy HH:mm"), Anchor = AnchorStyles.None, Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), AutoSize = true }, 3, tableLayoutPanel_dataLogs.RowCount - 1);
    tableLayoutPanel_dataLogs.Controls.Add(new Label() { Name = ControlNames.labelEntriesName + row, Text = currentEntriesCount, Anchor = AnchorStyles.None, Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), AutoSize = true }, 4, tableLayoutPanel_dataLogs.RowCount - 1);

    string tbName = ControlNames.textBoxFileNameName + row;
    tableLayoutPanel_dataLogs.Controls.Add(new TextBox() { Name = tbName, Text = String.Empty, Enabled = false, Anchor = AnchorStyles.Left, Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), AutoSize = true }, 5, tableLayoutPanel_dataLogs.RowCount - 1);
    TextBox tb = this.Controls.Find(tbName, true).First() as TextBox;
    tb.TextChanged += new System.EventHandler(this.textBoxFileName_TextChanged);

    tableLayoutPanel_dataLogs.Controls.Add(new PictureBox() { Name = ControlNames.pictureBoxName + row, Image = global::DataKey_Application.Properties.Resources.check_small, Text = "", Enabled = false, Visible = false, Margin = new System.Windows.Forms.Padding(0, 0, 0, 0), SizeMode = PictureBoxSizeMode.AutoSize, Anchor = AnchorStyles.Left }, 6, tableLayoutPanel_dataLogs.RowCount - 1);
    }

tableLayoutPanel_dataLogs.ResumeLayout(); 
tableLayoutPanel_dataLogs.PerformLayout();
tableLayoutPanel\u dataLogs.Visible=false;
tableLayoutPanel_dataLogs.SuspendLayout();
对于(int i=0;i
当垂直滚动条出现时,停靠会改变桌子上的宽度。你的最小尺寸可能不允许它变小。

好的,是时候挖掘这个问题并回答我自己的问题了(再次)。我回到这个问题上来,因为我的
表格布局面板
在从一个长长的列表开始时没有正确调整大小(例如,需要自动滚动)回到一个小列表。我从@Bioukh中吸取了一个想法,将
表格布局面板
放到
面板
中。该面板定义了
表格布局面板
的最大大小,该面板以Dock=top停靠在内部,并禁用了自动滚动。就在我绘制表格之前,我检查了它的首选高度并启用了自动滚动当我清除表格时,我也会在面板上禁用autoscroll。这既可以确保表格在应该显示的时候显示滚动条(没有图形故障),也可以确保表格小时面板滚动条消失

绘制表格后:

tableLayoutPanel_dataLogs.ResumeLayout(); 
tableLayoutPanel_dataLogs.PerformLayout();
if (tableLayoutPanel_dataLogs.GetPreferredSize(new Size()).Height > panel1.Size.Height) 
    panel1.AutoScroll = true;
tableLayoutPanel_dataLogs.Visible = true;
tableLayoutPanel_dataLogs.SuspendLayout();

TableLayoutControlCollection controls = tableLayoutPanel_dataLogs.Controls;
for (int i = controls.Count - 1; i > 0; i--)
{
    if (tableLayoutPanel_dataLogs.GetCellPosition(controls[i]).Row != 0)
    {
        Control control = controls[i];
        if (control.Name.Contains(ControlNames.checkBoxSelectedName)) ((CheckBox)control).CheckedChanged -= new System.EventHandler(this.checkBox_getAnyDataLog_CheckedChanged);
        else if (control.Name.Contains(ControlNames.textBoxFileNameName)) ((TextBox)control).TextChanged -= new System.EventHandler(this.textBoxFileName_TextChanged);
        controls.Remove(control);
        control.Dispose();
    }
}

while (tableLayoutPanel_dataLogs.RowCount > 1)
{
    int row = tableLayoutPanel_dataLogs.RowCount - 1;
    tableLayoutPanel_dataLogs.RowStyles.RemoveAt(row);
    tableLayoutPanel_dataLogs.RowCount--;
}
tableLayoutPanel_dataLogs.Size = new System.Drawing.Size(420, 56);
tableLayoutPanel_dataLogs.Visible = false;
tableLayoutPanel_dataLogs.ResumeLayout();
tableLayoutPanel_dataLogs.PerformLayout();
panel1.AutoScroll = false;
panel1.PerformLayout();
checkBoxes.Clear();
清理表格:

tableLayoutPanel_dataLogs.ResumeLayout(); 
tableLayoutPanel_dataLogs.PerformLayout();
if (tableLayoutPanel_dataLogs.GetPreferredSize(new Size()).Height > panel1.Size.Height) 
    panel1.AutoScroll = true;
tableLayoutPanel_dataLogs.Visible = true;
tableLayoutPanel_dataLogs.SuspendLayout();

TableLayoutControlCollection controls = tableLayoutPanel_dataLogs.Controls;
for (int i = controls.Count - 1; i > 0; i--)
{
    if (tableLayoutPanel_dataLogs.GetCellPosition(controls[i]).Row != 0)
    {
        Control control = controls[i];
        if (control.Name.Contains(ControlNames.checkBoxSelectedName)) ((CheckBox)control).CheckedChanged -= new System.EventHandler(this.checkBox_getAnyDataLog_CheckedChanged);
        else if (control.Name.Contains(ControlNames.textBoxFileNameName)) ((TextBox)control).TextChanged -= new System.EventHandler(this.textBoxFileName_TextChanged);
        controls.Remove(control);
        control.Dispose();
    }
}

while (tableLayoutPanel_dataLogs.RowCount > 1)
{
    int row = tableLayoutPanel_dataLogs.RowCount - 1;
    tableLayoutPanel_dataLogs.RowStyles.RemoveAt(row);
    tableLayoutPanel_dataLogs.RowCount--;
}
tableLayoutPanel_dataLogs.Size = new System.Drawing.Size(420, 56);
tableLayoutPanel_dataLogs.Visible = false;
tableLayoutPanel_dataLogs.ResumeLayout();
tableLayoutPanel_dataLogs.PerformLayout();
panel1.AutoScroll = false;
panel1.PerformLayout();
checkBoxes.Clear();

我尝试过更改最小大小,但没有效果。我还尝试过将自动大小模式更改为“增长和收缩”。它以前是“仅增长”。仍然会出现问题。只是出于好奇,它是双缓冲的吗?还有,复选标记是如何添加的?它是该单元格内的图像还是单元格本身的图像?我不相信它是双缓冲的(或者至少,我没有做任何事情来专门实现双缓冲区)。在添加/删除行之前,我会执行
tableLayoutPanel.Visible=false
。然后根据