473,378 Members | 1,110 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

ListBox with background image

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.

Expand|Select|Wrap|Line Numbers
  1.     class ListboxWithBgimage : ListBox
  2.     {
  3.         // Property does not accept null, weird
  4.         Image bgImage = Resources.list_log;
  5.  
  6.         public ListboxWithBgimage() : base()
  7.         {
  8.             // Make sure the OnPaint event triggers
  9.             this.SetStyle(ControlStyles.UserPaint, true);
  10.         }
  11.  
  12.         public override Image BackgroundImage
  13.         {
  14.             get { return bgImage; }
  15.             set { bgImage = value; }
  16.         }
  17.  
  18.         protected override void OnPaint(PaintEventArgs e)
  19.         {
  20.             Graphics g = e.Graphics;
  21.             g.DrawImage(bgImage, new PointF(0, 0));
  22.         }
  23.     }
  24.  
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.
Jun 8 '12 #1
0 2324

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Markus Mohr | last post by:
Hi, everyone, I have a special problem: For every monitor resolution in 200 pixel steps from 800 to 1600 pixels I have an image to be shown as centered background-image. Those images all...
4
by: Dj Frenzy | last post by:
Hi, I know how to use javascript to change a background image to another background image, and how to change a background colour to another background colour. Is there a way to change an image to a...
2
by: day | last post by:
I'm trying to use a non-scrolling background image within a div (the non-scrolling part is a "nice-to-have" vs a "have to have"). The style for that is: <div style="height=400px;...
7
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css...
3
by: Sridhar | last post by:
Hi, I have created a user control which has the html code as follows <TABLE id="ToolBarTable" cellSpacing="0" cellPadding="0" width="100%" border="0"> <tr> <td align="right"...
1
by: Kits | last post by:
Hi, Is it possible to put a background image in a listBox control?? How can this be done? Specifically I would like to display an image in the are of a listbox which is not occuppied by any...
1
by: rege | last post by:
Hi, Is it possible to put a background image in a listBox control?? How can this be done? Specifically I would like to display an image in the are of a listbox which is not occuppied by any...
3
by: KNDesign | last post by:
I've set a background image to repeat-y and at 100% height. It appears fine when I open the window, but when I resize to a smaller height so that I must scroll down to see the rest, the background...
16
by: stevedude | last post by:
CSS newbie again. I have a problem trying to get coffee mug images within anchor tags to center with my link text for a vertical list menu. If I use the horizontal/vertical properties of...
2
by: thephatp | last post by:
I'm having a problem with IE rendering correctly. I'm experimenting with using all div's in my pages now, and I'm not very familiar with the quirks of IE. I have created a sample page, and I'm...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.