编程分配保证金和/或填充到一个标签 [英] Programmatically assigning Margin and/or Padding to a Label

查看:102
本文介绍了编程分配保证金和/或填充到一个标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试让TableLayoutPanel中的一些标签从单元格的左上角移动到单元格的中心时,我想尝试添加填充和/或边距。

In trying to get some labels in a TableLayoutPanel to move from the top left of their cells to the center of the cells, I'm trying to experiment with adding padding and/or margins.

但是,我没有尝试过的工作。这里是我试过的代码和结果:

However, nothing I've tried works. Here's the code I've tried and the results:

// 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


推荐答案

Try:

lbl.Margin = new Padding(1);

您可能还想做:

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

这篇关于编程分配保证金和/或填充到一个标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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