473,624 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Wordwrap in VB.Net listbox?

Hi, If this has been answered before I am sorry, but I want to wordwrap
the items in a listbox so I dont have to use the horizontal scroll bar.
Is this possible? if so how can it be done?

Regards,
Craig.

Jan 16 '06 #1
4 11706
Hi,

You would have to make your listbox owner drawn

Public Class Form1

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListBox1.DrawMo de = DrawMode.OwnerD rawVariable
For x As Integer = 1 To 3
ListBox1.Items. Add(String.Form at("Line {0} that is way way way
to long to fit inside the listbox with out a scroll bar", x))
Next
End Sub

Private Sub ListBox1_DrawIt em(ByVal sender As Object, ByVal e As
System.Windows. Forms.DrawItemE ventArgs) Handles ListBox1.DrawIt em
Dim g As Graphics = e.Graphics
Dim br As SolidBrush
Dim s As String

Try
s = ListBox1.Items. Item(e.Index).T oString
Catch ex As Exception
Trace.WriteLine (ex.ToString)
s = "error"
End Try

g.FillRectangle (Brushes.White, e.Bounds)

If CBool(e.State And DrawItemState.S elected) Then
g.FillRectangle (Brushes.LightB lue, e.Bounds)
End If

br = New SolidBrush(Colo r.Black)

g.DrawString(s, ListBox1.Font, br, _
RectangleF.op_I mplicit(e.Bound s))

br.Dispose()
End Sub
Private Sub ListBox1_Measur eItem(ByVal sender As Object, ByVal e As
System.Windows. Forms.MeasureIt emEventArgs) Handles ListBox1.Measur eItem
Dim g As Graphics = e.Graphics
Dim s As String

Try
s = ListBox1.Items. Item(e.Index).T oString
Catch ex As Exception
s = "error"
End Try
Dim sz As SizeF = g.MeasureString (s, ListBox1.Font, ListBox1.Width _
- 5 - SystemInformati on.VerticalScro llBarWidth)
e.ItemHeight = CInt(sz.Height) + 5
e.ItemWidth = CInt(sz.Width) + 15
End Sub
End Class
Ken
-------------------
"the_mikado " <cr**********@a lcoa.com.au> wrote in message
news:11******** *************@g 49g2000cwa.goog legroups.com...
Hi, If this has been answered before I am sorry, but I want to wordwrap
the items in a listbox so I dont have to use the horizontal scroll bar.
Is this possible? if so how can it be done?

Regards,
Craig.

Jan 16 '06 #2
Hi Craig,

Apart from Ken's correct answer, can you consider making resizable the
window containing the list? While most people hate horizontal scrolling, a
listbox with wordwrap may appear even stranger, and what most people really
would like is to resize the windows of the apps to use the large monitors of
today... just a suggestion.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
"the_mikado " <cr**********@a lcoa.com.au> escribió en el mensaje
news:11******** *************@g 49g2000cwa.goog legroups.com...
Hi, If this has been answered before I am sorry, but I want to wordwrap
the items in a listbox so I dont have to use the horizontal scroll bar.
Is this possible? if so how can it be done?

Regards,
Craig.

Jan 16 '06 #3
Thanks to all who replied. The reason I need wordwrap is that we are
implementing a touchscreen listbox with large listbox items & fonts. A
horizontal toolbar is impractical but the text strings are too long.

Reagrds,
Craig.

Jan 16 '06 #4
Thanks Ken, I will try this.

Regards,
Craig.

Jan 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2693
by: lawrence | last post by:
When users enter urls or other long strings it can destroy the formatting of a page. A long url, posted in a comment, can cause page distortions that make the page unreadable, till the website owner logs in and deletes the comment. To protect against that, I'd like to break up long strings in the comments (anything submitted by anonymous sources). One thing I'd like to add to the following function is the ability to break up long...
6
1930
by: Pierre Jelenc | last post by:
I need to wrap text with a negative indent, that is this: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,...
0
1249
by: Richard Back | last post by:
Hi, I would like to print the contents of a textbox to a printer, and for the text to wordwrap. The text could be more than one pages worth so I need to track the pages. I can get it to track the pages (by reading a row at a time), and I can get it to word wrap (by putting it in a rectangle) but I can't get it to do both!
0
2446
by: Mike | last post by:
Hi All, I mistakenly just posted this to the VB group. Sorry for the cross-post. I am working with a textbox in C# which pulls a set of lines (stored in the database as text_type, text_line_seq, text_desc). I am using three text boxes to display previously entered text for selected users (surgeons) to edit. Each type of line has a specific maximum length (55,56, and 74 characters). The textbox must allow the users to format
1
1893
by: louise raisbeck | last post by:
Hi there, I create a report online with basically a dump of loads of tables. One of them has 27 columns and as such it ignores the datagrid.width property and goes right along the screen in a landscape fashion. the users want to print out in portrait however and i cant work out how to tell .net to wordwrap at column no. x ?? Any ideas? I can query how many columns there are but cant seem to get into the datagrid at the point of this...
2
2817
by: yxq | last post by:
Hello, The length of Tooltip string is not fixed, how to wordwrap according to width size? Where to find a function to return Multi-lines string from a long string? Thank you
1
2696
by: Cesar Ronchese | last post by:
Hi! I'm using a DataGridView to show a datatable that have many columns. When it displays data, the lines are applying wordwrap in some cells, because the grid is too wider to page. I'm wanting to do that DataGrid cells always show only one line of text, indepent of text size within it. It's possivel to do it? Ps: I set the RowStile.Wrap = False, but did not work.
0
340
by: the_mikado | last post by:
Hi, If this has been answered before I am sorry, but I want to wordwrap the items in a listbox so I dont have to use the horizontal scroll bar. Is this possible? if so how can it be done? Regards, Craig.
0
1464
by: Harvey Triana | last post by:
Hi -- How to do a GridView without wordwrap ? <HT/> Thanks
0
8240
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8625
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8336
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6111
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4082
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1487
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.