Notifications
Clear all

[Closed] dotnet List View Horizontal Padding

is there any setting in listView [properties or something] that making horizontal padding become not so far for each control.

currentlly

become something like this

currently im using this setup


	fn initLv theLv =
  		(
  			theLv.View = (dotNetClass "System.Windows.Forms.View").LargeIcon
  			theLv.Multiselect = true
  			theLv.Scrollable = true
			theLv.margin =dotnetobject "System.Windows.Forms.Padding" 1 --doesnt work
			theLv.Padding  =dotnetobject "System.Windows.Forms.Padding" 1 --this doesnt work
  		)

thanks for the guidance :love:

6 Replies

Thanks mr.Lo , but im not that advanced user ,still in progress of learning in dotnet ms, could you ascend how to use it in my ms… I know little bit of compiling thing in ms but still dont know how to use it tho.


fn compileThis =
(
	title  =""
	title+="using System.Runtime.InteropServices;
"
	title+="[DllImport(\"user32.dll\")]
"
	title+="public static extern int SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
"
	title+="public int MakeLong(short lowPart, short highPart)
"
	title+="{
"
	title+="	return (int)(((ushort)lowPart) | (uint)(highPart << 16));
"
	title+=" }
"
	title+="public void ListViewItem_SetSpacing(ListView listview, short leftPadding, short topPadding)
"
	title+="{
"
	title+= "	const int LVM_FIRST = 0x1000;
"
	title+="	const int LVM_SETICONSPACING = LVM_FIRST + 53;
"
	title+="	SendMessage(listview.Handle, LVM_SETICONSPACING, IntPtr.Zero, (IntPtr)MakeLong(leftPadding, topPadding));
"
	title+="}
"
	
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters" 
	compilerParams.ReferencedAssemblies.AddRange #("user32.dll","System.Windows.Forms.dll"); 
	compilerParams.GenerateInMemory = true
	compilerResults = (dotnetobject "Microsoft.CSharp.CSharpCodeProvider").CompileAssemblyFromSource compilerParams #(title)
	
)
compileThis()
 
 (
  	Global myScenes # ()
  	Global imageList = dotNetObject "System.Windows.Forms.ImageList"	
  	try destroyDialog myImageTest catch()
  	Rollout myImageTest "Scenes" width:500 height:500
  	(
  		dotNetControl sceneLv "System.Windows.Forms.ListView" width:480 height:480 
  		
  		fn initLv theLv =
  		(
  			theLv.View = (dotNetClass "System.Windows.Forms.View").largeIcon
  			theLv.Multiselect = true
  			theLv.Scrollable = true
			theLv.margin =dotnetobject "System.Windows.Forms.Padding" 1
			theLv.Padding  =dotnetobject "System.Windows.Forms.Padding" 1
  		)
  				
  		fn fillLv theLv =
  		(
			colorclass = (dotnetclass "system.drawing.color")
			
  			theLv.Clear()
  			theLv.items.Clear()	
  			theLv.Refresh()
  			imageList.images.Clear()
  			imageList.Dispose()
  
  			imageList.imagesize =  dotnetobject "System.Drawing.Size" 150 150
  			imageList.ColorDepth = imageList.ColorDepth.Depth32Bit
  			
			theLv.backcolor = theLv.backcolor.fromARGB 50 50 50
			theLv.forecolor = colorClass.white
			
  			local thumbs = #()
  			local items = #()
  			
  			for s = 1 to myScenes.count do
  			(

				
  				filePrefix = (getFilenamePath myScenes[s]) + (getFilenameFile myScenes[s])
				thumbFile =  filePrefix + ".jpg"
  				maxFile = filePrefix + ".max"
  				
  				append thumbs ((dotNetClass "System.Drawing.Image").fromFile thumbFile)
				
				item = dotNetObject "System.Windows.Forms.ListViewItem" (filenameFromPath maxFile)
  				item.name = maxFile
  				
  				item.imageIndex = s - 1
				
				--myborder=dotNetObject "System.Windows.Forms.BorderStyle.Fixed3D"
				
				
  				theLv.items.add item
  			)
  
  			imageList.images.addrange thumbs
  			
  			theLv.LargeImageList = imageList
  			theLv.SmallImageList = imageList
  			
  			for t in thumbs do t.dispose()
  		)
  		
  		on sceneLv mouseUp arg do
  		(	
  			hit=(sceneLv.HitTest (dotNetObject "System.Drawing.Point" arg.x arg.y))
  			if(hit != undefined AND hit.item != undefined) then
  			(	
  				-- hit.item.name has full path of max scene
  				print hit.item.name
  			)
  		)
  		
  		fn collectScenes =
  		(
  			myScenes = getFiles "D:\\*.max"
  		)
  		
  		on myImageTest open do
  		(
  			initLv sceneLv
  			collectScenes()
  			fillLv sceneLv
  		)
  		
  		on myImageTest close do
  		(
  			imageList.dispose()	
  		)
  		
  	)
  	createDialog myImageTest	
  )

where i must put the “ListViewItem_SetSpacing(this.listView1, 64 + 32, 100 + 16);” line ?

thanks for your answer.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

you don’t need any on-fly compiled assembly. you can do it with pure mxs. the only thing that you need is to send the right message to the right control. it’s one line of code… if you can wait i will show it tomorrow.

Ok thanks …will wait till tomorrow then, right now just try a thing up.
Thanks denisT

 lo1
fn setListViewSpacing lv leftPadding topPadding =
(
	local hWnd = lv.handle
	local LVM_SETICONSPACING = 0x1000 + 53
	local lParam = bit.or (bit.shift topPadding 16) leftPadding
	windows.SendMessage hWnd LVM_SETICONSPACING 0 lParam			
)

Keep in mind that:
[ul]
[li]The listview must already be created (it must have a valid handle)
[/li][li]The values for padding must include the size of the icons, otherwise you will get an invalid result. For example, in your case, to get 0 padding between the icons, you must pass values of 150 and 150 for the padding.
[/li][li]Sending a value of -1 will reset the padding to default.
[/li][/ul]

Thank you so much Mr.Lo, your function just work fine. :applause: :love: