Notifications
Clear all

[Closed] listView paint event

 PEN

I have never tried painting in a listView and it doesn’t appear to be straight forward. ownerDraw is supposed to be set to true but that stops the header and items from showing up that I’m adding.

Any one used the paint even in a listView? Have any tips?

16 Replies
1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

when you set ownerDraw to true it means you want to draw everything yourself. What do you really need to draw?

 PEN

Not that much so I’m going another root. Thanks Denis.

1 Reply
(@denist)
Joined: 11 months ago

Posts: 0

actually it’s not too bad to draw yourself. you can delegate the default drawing to the framework, and do custom drawing for only specific things. so… i’m asking again… what do you specifically want to draw?

Hey Denis, Id love to know if you can restyle the header bar of a listbox with ownerdraw, I haven’t found out how to do it up until now and I hate the way the grey windows header looks, especially with a dark UI. If you know how to restyle it to change the backcolor and remove the bevel edge that would be awesome. From what i can make out, it seems more complicated that the usual owner draw methods -? :shrug:

http://www.codeproject.com/KB/list/customheader.aspx

 PEN

The header for one as Pete would like as well and I would paint into the rows below the text, so I know that I would have paint The text in as well? I want the look of it to match the right hand portion of this tool.

At the moment I have made my own list using flowLayoutPanel and labels as I only need one column. This change is not seen in the image below.

Paul,
you can hide default Headers. Set HeaderStyle to None and draw a Label of any look above ListView.

But it’s has to be possible to do user draw for only Headers. As I have time i will make a snippet. Hopefully it will happen this weekend.

it was easier than i thought:


  try(form.close()) catch()
  form = dotnetobject "MaxCustomControls.MaxForm"
  form.size = dotnetobject "System.Drawing.Size" 200 200
  	
  lv = dotnetobject "ListView"
  lv.view = lv.view.Details
  lv.columns.add "Name"
  lv.columns.add "Sub"
  
  (
  	item = lv.items.add "Item"
  	item.subitems.add "Sub Item"
  )
  	
  lv.Dock = lv.Dock.Fill
  lv.FullRowSelect = on
  
  lv.OwnerDraw = on
  	
  fn onDrawColumnHeader s e =
  (
  --	print (e.State.ToString())
  	if (dotnet.CompareEnums e.State e.State.Selected) then
  	(
  		e.Graphics.FillRectangle (dotnetclass "System.Drawing.Brushes").Maroon e.Bounds
  	)
  	else
  	(
  		brush = dotnetobject "System.Drawing.Drawing2D.LinearGradientBrush" e.Bounds \
  			(dotnetclass "System.Drawing.Color").Orange \
  			(dotnetclass "System.Drawing.Color").Maroon \
  			(dotnetclass "System.Drawing.Drawing2D.LinearGradientMode").Vertical
  
  		e.Graphics.FillRectangle brush  e.Bounds
  	)
  	
  	flags = dotnet.combineEnums (dotnetclass "TextFormatFlags").HorizontalCenter (dotnetclass "TextFormatFlags").VerticalCenter
  	(dotnetclass "TextRenderer").DrawText e.Graphics e.Header.Text s.Font e.Bounds (dotnetclass "System.Drawing.Color").White flags
  )	
  fn onDrawItem s e =
  (
  	e.DrawDefault = on
  )	
  fn onDrawSubItem s e =
  (
  	e.DrawDefault = on
  )	
  dotnet.addEventHandler lv "DrawColumnHeader" onDrawColumnHeader
  dotnet.addEventHandler lv "DrawItem" onDrawItem
  dotnet.addEventHandler lv "DrawSubItem" onDrawSubItem
  
  form.controls.add lv	
  form.showmodeless()
  

PS. it’s not optimized! no time for that.

 PEN

Thanks Denis, i tried some of that but wasn’t able to get any of it to work so it will be good to go over the code you have.

man – for some reason when i looked on the web everyone seemed to be using win32 calls so I assumed it was more involved. Thanks a million Denis, great work as usual.

2 Replies
 PEN
(@pen)
Joined: 11 months ago

Posts: 0

That is what I found as well Pete, I couldn’t make heads or tails of it all in Max Script so gave up. I might stick with what I have how ever as it is even easier then what Denis has there I think. Just not sure which is faster.

Pete what do you think of the new joystick system?

(@lonerobot)
Joined: 11 months ago

Posts: 0

new system looks awesome Paul. I like the look of the pose bank on the side for facial animation. How are you hooking them up? callbacks?

 PEN

After a quick look I definitely didn’t try any of this. Had the events right and that was about it. Thanks again Denis. I will have to do some reading now to sort out what you have done.

hm… i can’t make header hotTracking … the draw event doesn’t catch Hot state. well. see it later.

Page 1 / 2