Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

ListBox entry with \n (multiline)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Stefan P. - 08 Mar 2008 17:35 GMT
Hi everyody,

I want to diplay strings of some objects in a LixtBox.
Sometimes the text is longer than my ListBox and a horizontal scrollbar
is displayed.

Is it possible to get the ListBox to display the Text in multiple lines
(per entry)?

I found some controls on CodeProject but they are to overloaded. I just
want to diplay the Text without scrolling (that every word of the stings
is visible on the first sight).

Greetings
Stefan
Barry Kelly - 09 Mar 2008 12:15 GMT
> I want to diplay strings of some objects in a LixtBox.
> Sometimes the text is longer than my ListBox and a horizontal scrollbar
> is displayed.
>
> Is it possible to get the ListBox to display the Text in multiple lines
> (per entry)?

Yes. Implement the ListBox.MeasureItem and ListBox.DrawItem events, and
set ListBox.DrawMode appropriately (OwnerDrawVariable). You'll need to
do the measuring and drawing yourself, unfortunately.

Check out Graphics.MeasureString and Graphics.DrawString methods and the
StringFormat class. It's not too difficult, and you have a lot of
flexibility. For example, you can put icons etc. in the listbox too, if
you like.

-- Barry

Signature

http://barrkel.blogspot.com/

Stefan P. - 09 Mar 2008 14:40 GMT
Hi Barry,

thanks. :)
I will try to do it this way.

Greetings Stefan

Barry Kelly schrieb:

>> I want to diplay strings of some objects in a LixtBox.
>> Sometimes the text is longer than my ListBox and a horizontal scrollbar
[quoted text clipped - 13 lines]
>
> -- Barry

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.