|
-
March 8th, 2010, 04:34 PM
#1
Listbox won't display anything in owner draw mode
I have a listbox which works perfectly fine in regular mode. I'm experimenting with the other modes which allow you to switch font.
As soon as I go to ownerdraw mode, either variable or fixed, it is blank when I try to add items to to it. It throws no error but just doesn't do anything. There has to be something else I have to do, to tell it how I want to display it. But I don't know what. I'm using version 2003 of .NET
I'm using "Items.add" to add items.
I'm using this line to set font :
lbox.Font = New Font("Arial", 8.25, FontStyle.Bold, GraphicsUnit.Point, Nothing)
Then I'm setting it unbold later.
Why is it working perfectly fine without owner draw? Granted it isn't changing the font but it's working fine. What do I have to do to make it work otherwise, so that I can change the font?
It's pretty much a standard listbox, without many changes made to the properties.
Last edited by Josef_Stalin; March 8th, 2010 at 04:45 PM.
-
March 8th, 2010, 06:54 PM
#2
Re: Listbox won't display anything in owner draw mode
Why use VS2003? There is 2005, 2008, and now, 2010 (still in beta, but available to everyone)
-
March 8th, 2010, 07:17 PM
#3
Re: Listbox won't display anything in owner draw mode
Compatibility reasons and I fiscal reasons.
-
March 9th, 2010, 12:16 AM
#4
Re: Listbox won't display anything in owner draw mode
There are FREE versions of ALL of them. The beta of VS2010 is the PRO version, and it's FREE as well
-
March 9th, 2010, 08:21 AM
#5
Re: Listbox won't display anything in owner draw mode
You need to use the ListBox's DrawItem event to draw the stuff 
For example :
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ListBox1.Items.Add("One")
ListBox1.Items.Add("Two")
ListBox1.Items.Add("Three")
End Sub
Private Sub ListBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ListBox1.DrawItem
Dim textFont As Font
textFont = New Font(e.Font.FontFamily, e.Font.Size * 2)
e.Graphics.DrawString(ListBox1.Items(e.Index).ToString(), _
textFont, _
New SolidBrush(e.ForeColor), _
e.Bounds.X, e.Bounds.Y)
e.DrawFocusRectangle()
End Sub
I agree that there are new versions of .NET available, but I also still have many 2003 programs, which will take an eternitity to port to newer versions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|