以编程方式为标签分配边距和/或填充。

6
在尝试将表格单元中的标签从左上角移动到单元格中心时,我尝试使用添加填充和/或边距的方法进行实验。
然而,无论我尝试了什么都没有奏效。以下是我尝试过的代码和结果:
// 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
2个回答

26

尝试:

lbl.Margin = new Padding(1);

你可能还想执行以下操作:

lbl.Dock = DockStyle.Fill;
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.AutoSize = false;

-6
labelName.Style.Add("Margin", "10px");

2
这个问题是关于Winforms的,这看起来像是javascript? - RoadieRich
这个答案对于一个WebForms应用项目来说是正确的。 - user3267567

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接