CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2005
    Posts
    43

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2005
    Posts
    43

    Re: Listbox won't display anything in owner draw mode

    Compatibility reasons and I fiscal reasons.

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    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
  •  





Click Here to Expand Forum to Full Width

Featured