Need a List Box with a Horizontal Scroll Bar 
Author Message
 Need a List Box with a Horizontal Scroll Bar

The standard VB6 Listbox control has a vertical scrollbar but not a
horizontal one.  Does anyone know of a Listbox type control that has a
horizontal scrollbar??


Wed, 18 Jun 1902 08:00:00 GMT  
 Need a List Box with a Horizontal Scroll Bar
Hi,

Try this small sample:

1. Open a new project
2. Place a List1 ListBox control on the Form
3. Copy the following code to the Form

'This message is used to set the ListBox'
'horisontal scrolling extent
Private Const LB_SETHORIZONTALEXTENT = &H194

Private Declare Function SendMessage Lib "user32" _
        Alias "SendMessageA" (ByVal hwnd As Long, _
                              ByVal wMsg As Long, _
                              ByVal wParam As Long, _
                              lParam As Any) As Long
Private Sub Form_Load()
    Dim sTemp As String
    Dim lLen As Long

    With List1
        'Narrow the ListBox width
        .Width = 2000

        'Add some items
        .AddItem "Short"
        .AddItem "Short string"
        sTemp = "Very long string, that might require a horisontal scroll
bar on the ListBox control in order to be able to view it."
        .AddItem sTemp

        'Adjust Listbox extent to the len of the longest string item.
        'This will cause a horisontal scroll bar to be shown.
        'NOTE that we need to convert the string length to pixels
        '     before sending it to the ListBox.

        'use the listbox font to check the size of the string
        Me.Font.Name = .Font.Name
        Me.Font.Size = .Font.Size
        Me.Font.Bold = .Font.Bold
        Me.Font.Italic = .Font.Italic

        'Find the text width (by default in TWIPS)
        lLen = Me.TextWidth(sTemp)

        'Convert the width to pixels
        lLen = lLen \ Screen.TwipsPerPixelX + 20

        'Set the new ListBox extents
        SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, lLen, ByVal 0&
    End With
End Sub

4. Run the project.

Regards,

Stoil

Quote:

> The standard VB6 Listbox control has a vertical scrollbar but not a
> horizontal one.  Does anyone know of a Listbox type control that has a
> horizontal scrollbar??



Wed, 18 Jun 1902 08:00:00 GMT  
 Need a List Box with a Horizontal Scroll Bar
Hi Stoil.  Thank you for your tip.  I tried it and it worked
perfectly! I really appreciate it.

I have never used this technique of sending a message to Windows (I
guess).  I would like to learn more about this technique.
Is there a good source for this kind of information.


On Tue, 17 Oct 2000 16:31:23 -0500, "Stoil Marinov"

Quote:

>Hi,

>Try this small sample:

>1. Open a new project
>2. Place a List1 ListBox control on the Form
>3. Copy the following code to the Form

>'This message is used to set the ListBox'
>'horisontal scrolling extent
>Private Const LB_SETHORIZONTALEXTENT = &H194

>Private Declare Function SendMessage Lib "user32" _
>        Alias "SendMessageA" (ByVal hwnd As Long, _
>                              ByVal wMsg As Long, _
>                              ByVal wParam As Long, _
>                              lParam As Any) As Long
>Private Sub Form_Load()
>    Dim sTemp As String
>    Dim lLen As Long

>    With List1
>        'Narrow the ListBox width
>        .Width = 2000

>        'Add some items
>        .AddItem "Short"
>        .AddItem "Short string"
>        sTemp = "Very long string, that might require a horisontal scroll
>bar on the ListBox control in order to be able to view it."
>        .AddItem sTemp

>        'Adjust Listbox extent to the len of the longest string item.
>        'This will cause a horisontal scroll bar to be shown.
>        'NOTE that we need to convert the string length to pixels
>        '     before sending it to the ListBox.

>        'use the listbox font to check the size of the string
>        Me.Font.Name = .Font.Name
>        Me.Font.Size = .Font.Size
>        Me.Font.Bold = .Font.Bold
>        Me.Font.Italic = .Font.Italic

>        'Find the text width (by default in TWIPS)
>        lLen = Me.TextWidth(sTemp)

>        'Convert the width to pixels
>        lLen = lLen \ Screen.TwipsPerPixelX + 20

>        'Set the new ListBox extents
>        SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, lLen, ByVal 0&
>    End With
>End Sub

>4. Run the project.

>Regards,

>Stoil


>> The standard VB6 Listbox control has a vertical scrollbar but not a
>> horizontal one.  Does anyone know of a Listbox type control that has a
>> horizontal scrollbar??



Wed, 18 Jun 1902 08:00:00 GMT  
 Need a List Box with a Horizontal Scroll Bar
Hi hdn,

Processing (receiving and sending) messages is all what windows programs are
about.
VB translates some of the received messages into the familiar events. Some
of the VB methods
result in sending messages, e.g.. the ListBox.AddItem() method calls the
SendMessage() API function
to send the LB_ADDSTRING message to the ListBox control.
VB and hides the Windows internal workings from the programmer.

The book that helped me understand how Windows work was "Programming
Windows" by Charles Petzold. All examples in there are in C. And this is not
the way to write Windows programs nowadays. But the book explains everything
that goes on behind the scenes.

Although I have not read it, I have seen the Daniel Appleman's book 'Visual
Basic Programmers Guide to the Win 32 API"
(http://www.desaware.com/VBPGWin32APIL2.htm) being recommended a lot in this
group.

And there always is the MSDN. This is the complete reference for all APIs,
standard Windows controls etc.
MSDN is available online at: http://msdn.microsoft.com/library/default.asp

For example, to learn how to use the SendMessage() API, you can go to:
http://msdn.microsoft.com/library/psdk/winui/messques_8ht1.htm

All ListBox control messages are listed and described at:
http://msdn.microsoft.com/library/psdk/winui/listbox_05rn.htm

Also, a good source of information are the VB news groups and the many VB
oriented Web sites.

Regards,

Stoil

Quote:

> Hi Stoil.  Thank you for your tip.  I tried it and it worked
> perfectly! I really appreciate it.

> I have never used this technique of sending a message to Windows (I
> guess).  I would like to learn more about this technique.
> Is there a good source for this kind of information.


> On Tue, 17 Oct 2000 16:31:23 -0500, "Stoil Marinov"

> >Hi,

> >Try this small sample:

> >1. Open a new project
> >2. Place a List1 ListBox control on the Form
> >3. Copy the following code to the Form

> >'This message is used to set the ListBox'
> >'horisontal scrolling extent
> >Private Const LB_SETHORIZONTALEXTENT = &H194

> >Private Declare Function SendMessage Lib "user32" _
> >        Alias "SendMessageA" (ByVal hwnd As Long, _
> >                              ByVal wMsg As Long, _
> >                              ByVal wParam As Long, _
> >                              lParam As Any) As Long
> >Private Sub Form_Load()
> >    Dim sTemp As String
> >    Dim lLen As Long

> >    With List1
> >        'Narrow the ListBox width
> >        .Width = 2000

> >        'Add some items
> >        .AddItem "Short"
> >        .AddItem "Short string"
> >        sTemp = "Very long string, that might require a horisontal scroll
> >bar on the ListBox control in order to be able to view it."
> >        .AddItem sTemp

> >        'Adjust Listbox extent to the len of the longest string item.
> >        'This will cause a horisontal scroll bar to be shown.
> >        'NOTE that we need to convert the string length to pixels
> >        '     before sending it to the ListBox.

> >        'use the listbox font to check the size of the string
> >        Me.Font.Name = .Font.Name
> >        Me.Font.Size = .Font.Size
> >        Me.Font.Bold = .Font.Bold
> >        Me.Font.Italic = .Font.Italic

> >        'Find the text width (by default in TWIPS)
> >        lLen = Me.TextWidth(sTemp)

> >        'Convert the width to pixels
> >        lLen = lLen \ Screen.TwipsPerPixelX + 20

> >        'Set the new ListBox extents
> >        SendMessage List1.hwnd, LB_SETHORIZONTALEXTENT, lLen, ByVal 0&
> >    End With
> >End Sub

> >4. Run the project.

> >Regards,

> >Stoil


> >> The standard VB6 Listbox control has a vertical scrollbar but not a
> >> horizontal one.  Does anyone know of a Listbox type control that has a
> >> horizontal scrollbar??



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. VB4, list boxes, and horizontal scroll bars CHALLENGE!

2. Adding horizontal scroll bars to a dir list box

3. Horizontal Scroll bar in List Box

4. adding horizontal scroll bar to list box

5. adding horizontal scroll bar to list box

6. Adding a horizontal scroll bar to File and Dir List Box

7. VB4, list boxes, and horizontal scroll bars CHALLENGE!

8. List Box: Adding a Horizontal and Vertical Scroll Bar

9. How do you add a horizontal scroll bar to a file list box control

10. Horizontal Scroll Bar for a list box VB4

11. Add Horizontal Scroll bar to List Box

12. List with horizontal scroll bar?

 

 
Powered by phpBB® Forum Software