我该如何以编程方式更改列表框的边距?

3
我正在尝试使用以下代码更改程序生成的列表框周围的边距:
newListBox.Margin = new Thickness(0, 0, 0, 0);

然而,这给我带来了错误:
the type or namespace Thickness could not be found

我尝试添加using System.Windows命名空间,但仍然收到相同的错误信息。请问有人能提供帮助吗?

3个回答

4

System.Windows.Thickness 是 Presentation Framework 的一部分。如果您没有使用 WPF 或 Silverlight,请尝试引用 PresentationFramework.dll 以获取访问 Thickness 结构的权限。

但是恐怕在这种情况下,您的 ListBox.Margin 不会接受 Thickness 类型的对象。如果您正在使用 WinForms,请尝试使用 System.Windows.Forms.Padding


2

我相信你正在寻找 Padding。请参阅Control.Margin

newListBox.Margin = new Padding(0, 0, 0, 0);

1

智能感知是你的好朋友。正如你所看到的,你想使用一个Padding对象。

enter image description here


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