在尝试让TableLayoutPanel中的某些标签从其单元格的左上角移动到单元格的中心时,我正在尝试添加填充和/或边距。
然而,我尝试过的任何东西都没有用。这是我尝试的代码和结果:
// Setting the padding just cuts off the bottom part of the text
//lbl.Padding = new System.Windows.Forms.Padding(1);
// How to set Margin?
//lbl.Margin = new System.Windows.Forms.Margin(1); <- This mimics "Padding" but is not recognized
//lbl.Margin = new Thickness(6); <- This is the only example I could find, but it's for WPF
答案 0 :(得分:15)
尝试:
lbl.Margin = new Padding(1);
您可能还想这样做:
lbl.Dock = DockStyle.Fill;
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.AutoSize = false;
答案 1 :(得分:-5)
labelName.Style.Add("Margin", "10px");