D
David Gouge
Hi All, appreciate that this is more gdi+ than c# but always seem to get
good answers here, so here goes...
In a nutshell, all i want to do is add a gradient background to a
ListView. I have gotten so far by:
Adding the following to the constructor:
this.SetStyle(ControlStyles.UserPaint, true);
And then overriding OnPaintBackground with the following:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
Graphics g = pevent.Graphics;
Rectangle rBackground = new Rectangle(0, 0, this.Width, this.Height);
System.Drawing.Drawing2D.LinearGradientBrush bBackground = new
System.Drawing.Drawing2D.LinearGradientBrush(rBackground,
Color.LightGoldenrodYellow, Color.White, (float)90);
g.FillRectangle(bBackground, rBackground);
}
Which works to a point; the listview has a nice gradient background, but
when items are added to the listview they do not show up and
subsequently when the listview is scrolled, the gradient gets 'messed
up'. I do not want to do anything special with the listview items
themselves, and as i scroll i would expect the gradient to stay put.
Complete beginner at gdi+, so any pointers / help would be appreciated.
Cheers,
Dave
good answers here, so here goes...
In a nutshell, all i want to do is add a gradient background to a
ListView. I have gotten so far by:
Adding the following to the constructor:
this.SetStyle(ControlStyles.UserPaint, true);
And then overriding OnPaintBackground with the following:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
Graphics g = pevent.Graphics;
Rectangle rBackground = new Rectangle(0, 0, this.Width, this.Height);
System.Drawing.Drawing2D.LinearGradientBrush bBackground = new
System.Drawing.Drawing2D.LinearGradientBrush(rBackground,
Color.LightGoldenrodYellow, Color.White, (float)90);
g.FillRectangle(bBackground, rBackground);
}
Which works to a point; the listview has a nice gradient background, but
when items are added to the listview they do not show up and
subsequently when the listview is scrolled, the gradient gets 'messed
up'. I do not want to do anything special with the listview items
themselves, and as i scroll i would expect the gradient to stay put.
Complete beginner at gdi+, so any pointers / help would be appreciated.
Cheers,
Dave