I've started a component and cannot work out how to get to the column headers to color them with a selected header color which I will add in the Appearance.
This code draws a line around the outside of the listView but does not incorporate the header.
I need a solution quick as I've spent to much time messing around with this.
Thanks
Redav
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Vectio.Controls
{
public class FlatListView : System.Windows.Forms.ListView
{
private Brush _borderBrush = new SolidBrush(Color.White);
private Color _borderColor = SystemColors.Control;
private bool _flatMode = true;
public FlatListView() : base()
{
}
[Category("Appearance"]
public Color BorderColor
{
get
{
return _borderColor;
}
set
{
_borderColor = value;
this.Invalidate();
}
}
[Category("Appearance"]
public bool FlatMode
{
get
{
return _flatMode;
}
set
{
_flatMode = value;
this.Invalidate();
}
}
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(!_flatMode) return;
if(m.Msg == 15)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black,.5F);
if(Enabled)
{
Pen eraser = new Pen(BackColor);
g.DrawRectangle(eraser, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width-1, ClientRectangle.Height-1);
g.DrawRectangle(eraser, ClientRectangle.Left+1, ClientRectangle.Top+1,ClientRectangle.Width, ClientRectangle.Height-3);
eraser.Dispose();
eraser = null;
}
else
{
g.FillRectangle(new SolidBrush(SystemColors.Control),ClientRectangle);
}
p.Width = .5F;
p.Color=BorderColor;
Rectangle rect2 = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
g.DrawRectangle(p,rect2);
{
}
}
}
This code draws a line around the outside of the listView but does not incorporate the header.
I need a solution quick as I've spent to much time messing around with this.
Thanks
Redav
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace Vectio.Controls
{
public class FlatListView : System.Windows.Forms.ListView
{
private Brush _borderBrush = new SolidBrush(Color.White);
private Color _borderColor = SystemColors.Control;
private bool _flatMode = true;
public FlatListView() : base()
{
}
[Category("Appearance"]
public Color BorderColor
{
get
{
return _borderColor;
}
set
{
_borderColor = value;
this.Invalidate();
}
}
[Category("Appearance"]
public bool FlatMode
{
get
{
return _flatMode;
}
set
{
_flatMode = value;
this.Invalidate();
}
}
protected override void WndProc(ref Message m)
{
base.WndProc (ref m);
if(!_flatMode) return;
if(m.Msg == 15)
{
Graphics g = this.CreateGraphics();
Pen p = new Pen(Color.Black,.5F);
if(Enabled)
{
Pen eraser = new Pen(BackColor);
g.DrawRectangle(eraser, ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Width-1, ClientRectangle.Height-1);
g.DrawRectangle(eraser, ClientRectangle.Left+1, ClientRectangle.Top+1,ClientRectangle.Width, ClientRectangle.Height-3);
eraser.Dispose();
eraser = null;
}
else
{
g.FillRectangle(new SolidBrush(SystemColors.Control),ClientRectangle);
}
p.Width = .5F;
p.Color=BorderColor;
Rectangle rect2 = new Rectangle(0, 0, this.Width - 1, this.Height - 1);
g.DrawRectangle(p,rect2);
{
}
}
}