By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

ListView with Gradient Background

P: n/a
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(rBack ground,
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
Sep 21 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.