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

时间:2012-11-07 19:50:51

标签: c# listbox margin

我正在尝试使用以下代码更改一组以编程方式生成的列表框:

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

然而,这给了我错误:

the type or namespace Thickness could not be found

我尝试添加using System.Windows命名空间,但我仍然遇到同样的错误。有人可以帮忙吗?

3 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:2)

我相信你正在寻找Padding。见Control.Margin

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

答案 2 :(得分:1)

Intellisense是你的朋友。如您所见,您想要使用Padding对象。

enter image description here