Results 1 to 10 of 10

Thread: listbox line height

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    5

    listbox line height

    Hi

    I have looked many places and I cannot find how to change the line height in a list box for Visual Basic 2013 using visual studio.

    In the properties panel - the paragraph line height is not editable when a list box properties is being set.

    Alternately

    lstBox.items.lineheight or lstBox.item.spacing is not an available option in 2013.

    Can anybody help?

    I need single spacing in the listbox. The default is double spacing for visual studio 2013 using Visual Basic

    Thanks to anyone who can help

    Jeanie

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,687

    Re: listbox line height

    While I'm not 100% positive in this, but I believe the line height is relative to the size of the font. Therefore a great font size equals a greater line height.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    5

    Re: listbox line height

    I appreciate that dday9. But it is different.
    I have successfully made a square of any size in a listbox like this with astericks:

    ****

    ****

    ****

    ****

    note the spacing from line to line. I want to shorten that line height. Older versions and other language programs allow to adjust the spacing between each line. I want the square to actually look like this:

    ****
    ****
    ****
    ****

    Any ideas on that?

    Courier New or segue - whichever font... I should be able to adjust that line spacing. I would love if someone knew this answer. I have not found a correct answer anywhere.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,972

    Re: listbox line height

    ummm.... HOW are you adding those lines? Listboxes by default single space... so if you're getting lines inbetween, you're doing it, maybe w/o realizing it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Frenzied Member Bulldog's Avatar
    Join Date
    Jun 2005
    Location
    South UK
    Posts
    1,950

    Re: listbox line height

    According to MSDN, the ItemHeight allows adjustment https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx


    • If my post helped you, please Rate it
    • If your problem is solved please also mark the thread resolved

    I use VS2015 (unless otherwise stated).
    _________________________________________________________________________________
    B.Sc(Hons), AUS.P, C.Eng, MIET, MIEEE, MBCS / MCSE+Sec, MCSA+Sec, MCP, A+, Net+, Sec+, MCIWD, CIWP, CIWA
    I wrote my very first program in 1979, using machine code on a mechanical Olivetti teletype connected to an 8-bit, 78 instruction, 1MHz, Motorola 6800 multi-user system with 2k of memory. Using Windows, I dont think my situation has improved.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    5

    Re: listbox line height

    thanks Bulldog

    That adjust the height of the actual item but not the space between the items.

    it is a button click event - When the button is clicked the program iterates through LstBox1 LB1 and creates a histogram using x's in LB2
    It calls upon a function xLines to create the line of exes to put into LB2

    I dont want to change the height of the x's... I just want to be able to adjust the line spacing between the x much like line spacing in a word doc or website build.

    Dim i as integer
    Dim line as String = ""
    Dim num as integer

    LB2.items.Clear()

    For i = 0 to LB1.Items.Count - 1
    num = LB1.Items(i)
    line = xLines(num)
    LB2.Items.Add(line)
    Next

    end Sub

    In the properties panel of visual studio there is a line height adjustment that should let me change this. It is under text in the properties panel. When I have the listbox clicked to adjust its properties it will not let me adjust that. Meaning it wont let me click in there to change the line height of the listbox.

    It sure seems this should be doable. But I do not seem to be able to find anyone who knows for sure how to do. Appreciate your help anyway.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    5

    Re: listbox line height

    Thanks techgnome

    see my response below if you like to see my code. I was more meaning it appears to be double spacing. I would just like to be able to adjust that spacing. There is nothing I am doing to create the spacing - it is the default in the program. My teacher and I were discussing that changing the line height is not intuitive for list box and the answer cant seem to be found. He didnt know how to change it but also wanted to know how it was done. it started bugging me that I cant find the answer for visual basic. I thought I would ask people who have a greater knowledge of the program that I do.
    thank you anyway

  8. #8
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: listbox line height

    Jeanieh,

    If you read the article Bulldog linked to you wil see that when the listbox drawmode is 'OwnerDrawnFixed'
    the Item Height will indeed space the row just about any distance apart you like.

    It means you have to write code to draw the text on each line though.

    Here is an inherited listbox that does just that.
    At design-time you set the DrawMode = OwnerDrawFixed and the Item Height to what ever you like.
    I set mine to 2 * font.height (2 * 8 = 16) to double the spacing for this example.
    Code:
    Public Class LeggyListBox
      Inherits ListBox
    
      Public Sub New()
        MyBase.New()
        Me.DoubleBuffered = True
      End Sub
    
      Protected Overrides Sub OnDrawItem(e As DrawItemEventArgs)
        MyBase.OnDrawItem(e)
    
        Try
          Dim g As Graphics = e.Graphics
          Dim sf As New StringFormat
          sf.FormatFlags = StringFormatFlags.NoWrap
          'sf.LineAlignment = StringAlignment.Near  ' Places the text at the top of the row.
          sf.LineAlignment = StringAlignment.Center ' Places the text in the center of the row.
    
          e.DrawBackground()
          With g
            .DrawString(Me.Items(e.Index).ToString, e.Font, New SolidBrush(e.ForeColor), e.Bounds, sf)
          End With
          e.DrawFocusRectangle()
        Catch
        End Try
    
      End Sub
    End Class
    The light blue list on the left is the leggylistbox.
    The white list on the right is a standard listbox.

    Name:  LeggyListbox.png
Views: 560
Size:  14.5 KB
    Last edited by Gruff; Apr 10th, 2015 at 06:32 PM.
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  9. #9
    Frenzied Member Gruff's Avatar
    Join Date
    Jan 2014
    Location
    Scappoose Oregon USA
    Posts
    1,293

    Re: listbox line height

    *** Duplicate ***
    Burn the land and boil the sea
    You can't take the sky from me


    ~T

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2015
    Posts
    5

    Re: listbox line height

    thanks Gruff
    I see now that it is doable but it is over my head at this point. We have not learned about drawmode at all.
    We are just beginning graphics and are at the stage of
    dim line as line = new line
    etc etc
    Our teacher doesnt teach according to a book and the book I do use is more in line with what you are saying. Its a 2010 book.

    I appreciate your help. I need to go back and learn more about how to set up draw mode.

    I understand what you are saying to do but I need to book that walks me through how to properly understand all the syntax like the me. and e. etc to properly set it up.

    Thanks again

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