C# 以编程方式为标签指定边距和/或填充

C# 以编程方式为标签指定边距和/或填充,c#,winforms,padding,margin,tablelayoutpanel,C#,Winforms,Padding,Margin,Tablelayoutpanel,在尝试让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 Syste

在尝试让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
//设置填充只会切断文本的底部
//lbl.Padding=newsystem.Windows.Forms.Padding(1);
//如何设定保证金?
//lbl.Margin=新系统.Windows.Forms.Margin(1) 尝试:

您可能还希望执行以下操作:

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

问题是关于Winforms,这看起来像javascript?
lbl.Dock = DockStyle.Fill;
lbl.TextAlign = ContentAlignment.MiddleCenter;
lbl.AutoSize = false;
labelName.Style.Add("Margin", "10px");