【问题标题】:How can I programmatically change a listbox margin?如何以编程方式更改列表框边距?
【发布时间】:2012-10-27 22:40:03
【问题描述】:

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

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

但是这给了我错误:

the type or namespace Thickness could not be found

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

【问题讨论】:

    标签: c# listbox margin


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2017-03-17
          • 1970-01-01
          • 1970-01-01
          • 2011-05-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多