Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I programmatically change a listbox margin?

Tags:

c#

margin

listbox

I am trying to change the margin around a set of programmatically generated listboxes using the following code:

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

However this gives me the error:

the type or namespace Thickness could not be found

I tried adding using System.Windows namespace but I still get the same error. Can anyone help please?

like image 594
user1696698 Avatar asked Dec 31 '25 00:12

user1696698


2 Answers

System.Windows.Thickness is part of the Presentation Framework. If you arent using WPF or Silverlight try referencing PresentationFramework.dll to get access to the Thickness structure.

But I'm afraid that in this case your ListBox.Margin won't accept an object of type Thickness. Try System.Windows.Forms.Padding if you're using WinForms.

like image 108
Dennis Traub Avatar answered Jan 01 '26 12:01

Dennis Traub


I believe you're looking for Padding. See Control.Margin

newListBox.Margin = new Padding(0, 0, 0, 0);
like image 27
Mike Park Avatar answered Jan 01 '26 14:01

Mike Park