Hi,
I have been trying to put a background image on a listbox control.
The only way I saw possible was to inherit the listbox control and override the OnPaint event.
There's still an issue with the background image scrolling (not staying in a fixed location) but I'll get to that eventually.
Right now my main issue is that items put into the listbox during design or runtime are not showing up at all. They appear transparent until highlighted in which case the highlight seems to stick.
Since I don't have much experience about this sort of code, I'm kind of confused as to what is causing this, or whether this is a known issue (with no workaround).
I certainly tried searching the web and found several people asking how to get this same thing done, but no one seems to encounter this problem, or even ask about it.
Has anyone else encountered the same issue, or knowns how to fix this? Im using VS2010 and C#.NET 3.5.
Thanks.
I have been trying to put a background image on a listbox control.
The only way I saw possible was to inherit the listbox control and override the OnPaint event.
Code:
class ListboxWithBgimage : ListBox
{
// Property does not accept null, weird
Image bgImage = Resources.list_log;
public ListboxWithBgimage() : base()
{
// Make sure the OnPaint event triggers
this.SetStyle(ControlStyles.UserPaint, true);
}
public override Image BackgroundImage
{
get { return bgImage; }
set { bgImage = value; }
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(bgImage, new PointF(0, 0));
}
}
Right now my main issue is that items put into the listbox during design or runtime are not showing up at all. They appear transparent until highlighted in which case the highlight seems to stick.
Since I don't have much experience about this sort of code, I'm kind of confused as to what is causing this, or whether this is a known issue (with no workaround).
I certainly tried searching the web and found several people asking how to get this same thing done, but no one seems to encounter this problem, or even ask about it.
Has anyone else encountered the same issue, or knowns how to fix this? Im using VS2010 and C#.NET 3.5.
Thanks.