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 / .NET Framework / New Users / May 2005

Tip: Looking for answers? Try searching our database.

Multi coloured text in a list view item

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan Kelley - 12 May 2005 13:01 GMT
I have asked this in the windowsforms forum, but thought I would try this one
too just in case. I am developing a game server browser winform application.
The app will query selected servers that are hosting a game (e.g. Quake 3),
and the server will send back a string with various info. One of these pieces
of info will be a
list of players names.

My problem is, players can colour their names using ^<char>, where <char> is
a number between 0 and 9, or a letter. I am currently using a list view to
display the list of players.

Is it at all possible to have multi coloured text in a list view, or similar
control? I have seen it done in other apps (although none that are written
using the .Net framework - for example All Seeing Eye). In a web page this
would be simple - simply wrap each of the letters in the players name that
are different from the previous letters colour in a <font> tag.

Just for the record, I am not interested in the RichTextBox control. This
data needs to be displayed in a grid-like control.

All help much appreciated.

Thanks
Dan
Morten Wennevik - 12 May 2005 16:09 GMT
Hi Dan,

As of Framework 2.0 you will be able to OwnerDraw ListView items, but until then you are out of luck.

> I have asked this in the windowsforms forum, but thought I would try this one
> too just in case. I am developing a game server browser winform application.
[quoted text clipped - 20 lines]
> Thanks
> Dan

Signature

Happy coding!
Morten Wennevik [C# MVP]

Dan Kelley - 13 May 2005 08:41 GMT
I suspected as much. As it happens, I have a the Express copy of C# at home.
I appreciate this is not a 2.0 forum, but do you have any info on how this
could be done in 2.0? Or any useful links.

Cheers
Dan

> Hi Dan,
>
[quoted text clipped - 24 lines]
> > Thanks
> > Dan
Morten Wennevik - 13 May 2005 08:59 GMT
Well, I haven't tried ownerdrawing ListView items yet, but the principles should be the same as ownerdrawing any other list.

I suppose you will need several calls to Graphics.DrawString, one for each time the color changes and to get the correct position for the next bit of text you will need to use Graphics.MeasureCharacterRanges.

This sample covers the basics of it.  You probably don't need to use MeasureItem.
You should note that for ListView you use the DrawListViewItemEventHandler/Args and OwnerDraw needs to be set to true.

> I suspected as much. As it happens, I have a the Express copy of C# at home.
> I appreciate this is not a 2.0 forum, but do you have any info on how this
[quoted text clipped - 35 lines]
>> Happy coding!
>> Morten Wennevik [C# MVP]

Signature

Happy coding!
Morten Wennevik [C# MVP]

Dan Kelley - 13 May 2005 12:41 GMT
Thanks Morten. I will take a look.

Dan

> Well, I haven't tried ownerdrawing ListView items yet, but the principles should be the same as ownerdrawing any other list.
>
[quoted text clipped - 42 lines]
> >> Happy coding!
> >> Morten Wennevik [C# MVP]

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.