无法删除TableLayoutPanel中控件之间的间距? [英] Cannot remove spacing between controls in TableLayoutPanel?

查看:593
本文介绍了无法删除TableLayoutPanel中控件之间的间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加到 TableLayoutPanel 的按钮之间有一些间距。我删除了按钮中的边框,并在面板中将边距和填充设置为0。但是我继续得到这个间距。

There's some spacing between the Buttons I add to my TableLayoutPanel. I removed the border in the Button and set the Margin and Padding to 0 in the Panel. But I continue getting that spacing.

tableLayoutPanel.RowCount设置为8,我添加的 Rows 集合8行,大小类型为绝对

tableLayoutPanel.RowCount is set to 8 and the Rows collection I've added 8 rows with Size Type Absolute.

我错过了什么吗?代码如下:

Am I missing something? Here's the code:

    private void FillSelectLayout()
    {
        tableLayoutPanelSelect.Controls.Clear();
        tableLayoutPanelSelect.RowStyles.Clear();

        tableLayoutPanelSelect.RowCount = 8;

        for (int i = 0; i < 8; i++)
        {
            Button buttonSelector = new Button();
            buttonSelector.Height = 64;
            buttonSelector.Width = 100;
            buttonSelector.FlatStyle = FlatStyle.Flat;
            buttonSelector.FlatAppearance.BorderSize = 0;
            buttonSelector.BackColor = Color.Yellow;
            tableLayoutPanelSelect.Controls.Add(buttonSelector, 0, i);
        }
    }

显示方式如下:

推荐答案

删除空格在单元格中的按钮之间设置,足以设置它们的停靠属性,然后删除按钮的默认边距:

To remove the space between buttons in cells, it's enough to set dock property of them to fill and then remove default margins of buttons:

var b = new Button();
b.Dock = DockStyle.Fill;
b.Margin = new Padding(0);

注意:


  • 通常最好将单元格中托管的控件的 Dock 属性设置为 Fill 。这样,您的控件将遵循 TableLayouPanel 为列和行设置的大小调整规则。

  • Usually it's better to set Dock property of controls which you host in cells to Fill. This way your controls will follow TableLayouPanel sizing rules which you set for columns and rows.

TableLayoutPanel 使用控件的 Margin 属性设置控件在单元格中的位置。因此,如果您不想设置 Dock ,而是希望手动设置 Size ,则足以设置保证金

TableLayoutPanel use Margin property of control to set the location of control in cell. So If you don'n want to set Dock and you prefer to set the Size manually, it's enough to set the Margin only.

这篇关于无法删除TableLayoutPanel中控件之间的间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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