Cannot remove spacing between controls in TableLayoutPanel?

前端 未结 3 1473
眼角桃花
眼角桃花 2021-01-24 11:17

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 c

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 11:42

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

    Note:

    • 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 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.

提交回复
热议问题