PDA

View Full Version : Can we change the color of dotNet listView's column header?


Jausn
09-01-2009, 01:21 AM
Can we change the column header's color?
Can we make the checkbox's background color to be the same as the listview's background color?

denisT
09-01-2009, 03:00 PM
Can we change the column header's color?
No, you can't. It's a system color

Can we make the checkbox's background color to be the same as the listview's background color?
If it's dotnet checkbox you can set the same back color as listview's
If it's MAX checkbox you can set listview's back color the same as check box's

c = ((colorman.getColor #background)*255) as color
lv.backcolor = (dotNetClass "System.Drawing.Color").fromARGB c.r c.g c.b

Jausn
09-02-2009, 01:27 AM
Sounds like we can't control the checkBox's background color. Is it so?

VVaari
09-02-2009, 06:49 AM
You can "change" the column header color by drawing the header yourself. I've never done any ownerdrawing code inside maxscript, I just create my own customlistview class derived from listview in Visual Studio. Here is a quick example which draws header and colors items background also.


using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Windows.Forms;

namespace CustomListNamespace
{
public class CustomList : ListView
{
public CustomList()
{
this.OwnerDraw = true;
this.DoubleBuffered = true;
}

protected override void OnDrawItem(DrawListViewItemEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Aqua, e.Bounds);
e.DrawText();
}

protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
{
e.Graphics.FillRectangle(Brushes.GreenYellow, e.Bounds);
e.DrawText();
}

}
}


OnDrawItem is called when item is being drawn and OnDrawColumnHeader when header is drawn. After build, just load your created dll assembly inside maxscript and you can use it like normal dotNet listview.

I don't know if this is the best way to do these kinds of things, but I like it because it's easier for me to control my listviews by adding custom functions to do stuff etc.

biddle
09-03-2009, 08:53 PM
If you are adding controls to a form you can add the required events to support ownerdraw manually and change the colour of the column header:


Brushes = dotnetclass "Drawing.Brushes"
fn CustomColumnDraw sender evt =
(
colour = if (mod evt.ColumnIndex 2) == 0 then Brushes.GreenYellow else Brushes.LawnGreen
evt.Graphics.FillRectangle colour evt.Bounds
evt.DrawText()
)

fn CustomItemDraw sender evt =
(
colour = if (mod evt.ItemIndex 2) == 0 then Brushes.Salmon else Brushes.PaleGreen
evt.Graphics.FillRectangle colour evt.Bounds
evt.DrawText()
)

fn test =
(
frm = dotNetObject "MaxCustomControls.MaxForm"
frm.Size = dotNetObject "System.Drawing.Size" 400 200
frm.Text= "ListView Custom Draw Test"

lv = dotnetobject "ListView"
lv.height = 190
lv.width = 390

frm.controls.add lv

dotnet.AddEventHandler lv "DrawItem" CustomItemDraw
dotnet.AddEventHandler lv "DrawColumnHeader" CustomColumnDraw

lv.OwnerDraw = true
lv.View = lv.View.Details

col0 = lv.columns.add "Column0"
col1 = lv.columns.add "Column1"
col2 = lv.columns.add "Column2"

col0.width = 100
col1.width = 100
col2.width = 100
itm0 = lv.items.add (dotnetobject "ListViewItem" "Item0" )
itm1 = lv.items.add (dotnetobject "ListViewItem" "Item1" )
itm2 = lv.items.add (dotnetobject "ListViewItem" "Item2" )

frm.show()
)
test()

Jausn
09-04-2009, 04:18 AM
It's a little complicated. But I'm trying to get it!
Thanks a lot!

CGTalk Moderation
09-04-2009, 04:18 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.