chanecolors of text in listbox

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 10 October 2012   #1
chanecolors of text in listbox

how do you change text colors in dotnet list box?
 
Old 10 October 2012   #2
Originally Posted by DannyBoy3: how do you change text colors in dotnet list box?

if you want to set the same color for all items use ForeColor property, if different you have to paint them yourself in DrawMode.OwnerDrawVariable using DrawItem event.
 
Old 10 October 2012   #3
Originally Posted by denisT: if you want to set the same color for all items use ForeColor property, if different you have to paint them yourself in DrawMode.OwnerDrawVariable using DrawItem event.

First solution that you mentioned is the best and is used by almost all .net objects (controls).
When i used draw mode in most situation i hed flickering problem. Also checkedListBox ctrl is
problematic. Workaround is ListView, powerful ctrl with more options.
My last script had similar concept like ActiveType script at the beginning, but i decide to start from scratch with ListView and I'm pleased with the result .
Denis i know that you not like colored UI but...
__________________
Looking in the right side. [bgaTools]
 
Old 10 October 2012   #4
Originally Posted by gazybara: When i used draw mode in most situation i hed flickering problem. Also checkedListBox ctrl is
problematic. Workaround is ListView, powerful ctrl with more options.

flickering is a problem for most .net window forms.
about using ListView in place of ListBox... ListBox is much faster!
 
Old 10 October 2012   #5
Originally Posted by denisT: flickering is a problem for most .net window forms.
about using ListView in place of ListBox... ListBox is much faster!

Yes you right, because there are more options than ListBox.
The situation is similar when comparing ListView and DataGridView or TreeList.
More powerful ctrls are always slower
__________________
Looking in the right side. [bgaTools]
 
Old 10 October 2012   #6
Thanks Branco. Had a look at yr script...nice usable struct there..but not quite what I need - I need to be able to change color of text within the listview on a per item basis(actually I just want yellow red blue for easy linking to ctrl object direction). in this case do I need to use drawitem?

Last edited by DannyBoy3 : 10 October 2012 at 12:07 AM.
 
Old 10 October 2012   #7
i made this code some years ago to test custom text and selection colours in a dotnet listbox. Should be helpful.

(
 	global dnListBoxTestRollout
 	try(destroyDialog dnListBoxTestRollout)catch()
 	
 	local dnColor = (dotNetClass "System.Drawing.Color").Black
 	local brushes = dotNetClass "System.Drawing.Brushes"
 	local brushColors = for p in (getPropNames brushes) collect p as string
 	local ListItems = for c in brushColors collect dotNetObject "System.String" c
 	local colorArr = for i in ListItems collect #(dnColor.red, dnColor.green, dnColor.blue)[random 1 3] --(dotNetClass "System.Drawing.Color").fromARGB (random 0 255) (random 0 255) (random 0 255)
 	
 	rollout dnListBoxTestRollout "dnListBoxTestRollout"
 	(
 		local selColor = (dotNetClass "System.Drawing.Color").fromARGB 238 204 85 -- custom selection color (orangey-yellow)
 		local lbBackColor = (dotNetClass "System.Drawing.Color").fromARGB 225 225 225 -- light grey
 		
 		local selBrush = dotNetObject "System.Drawing.SolidBrush" selColor -- create a brush for the selection color
 		local bgBrush = dotNetObject "System.Drawing.SolidBrush" lbBackColor -- create a brush for the backcolor
 		
 		
 		dotNetControl dnListBox "System.Windows.Forms.Listbox" height:400 -- the ListBox
 		radioButtons rdo_exampleMode "Examples:" labels:#("Custom Selection Color", "Named Brushes Colors","Colored Base Off Array") offset:[0,-30] columns:3
 		
 		
 		on rdo_exampleMode changed state do dnListBox.Refresh() -- toggle the drawing state
 		
 		on dnListBox DrawItem arg do --if arg.index == 0 do
 		(
 			case rdo_exampleMode.state of
 			(
 				1: -- use a custom selection color and alternating text color
 				(
 					-- we need to draw a background rectangle first
 					stringState = arg.state.ToString() -- convert the item state to a string
 					-- test the pattern of the string to see if it contains 'selected' since it can contain multiple states eg 'Selected, Focus'
 					if matchPattern stringState pattern:"*selected*" then arg.Graphics.FillRectangle selBrush arg.bounds -- draw the selection color
 					else arg.DrawBackground() -- else draw the background color
 					
 					-- alternatively draw the background color yourself:
 					-- arg.Graphics.FillRectangle bgBrush arg.bounds
 				   
 					-- define a brush to paint the text color
 					brush = if mod arg.index 2 == 0 then brushes.Red else brushes.Black -- alternate between red and black
 					arg.Graphics.DrawString dnListBox.Items.Item[arg.index] arg.font brush arg.bounds.location.x arg.bounds.location.y -- draw the text string
 				)
 				2: -- this mode is not made for selecting - just a demo of the built in colors
 				(
 					-- we need to draw a background rectangle first
 					fillBrush = getProperty brushes brushColors[arg.index+1] -- choose the current brush color by name from the brushes class
 					arg.Graphics.FillRectangle fillBrush arg.bounds -- draw the background
 				   
 					-- define a brush to paint the text color
 					brush = if fillBrush.color.getBrightness() >= 0.5 then brushes.black else brushes.white -- choose black or white based on brightness
 					arg.Graphics.DrawString dnListBox.Items.Item[arg.index] arg.font brush arg.bounds.location.x arg.bounds.location.y -- draw the text string
 				)
 				3: -- assign colors based off a predefined array. To change a color just change the array color and call invalidate() on that item's rectangle
 				(
 					-- we need to draw a background rectangle first
 					stringState = arg.state.ToString() -- convert the item state to a string
 					-- test the pattern of the string to see if it contains 'selected' since it can contain multiple states eg 'Selected, Focus'
 					if matchPattern stringState pattern:"*selected*" then arg.Graphics.FillRectangle selBrush arg.bounds -- draw the selection color
 					else arg.DrawBackground() -- else draw the background color
 					
 					-- define a brush to paint the text color
 					brush = dotNetObject "System.Drawing.SolidBrush" colorArr[arg.index+1]
 					arg.Graphics.DrawString dnListBox.Items.Item[arg.index] arg.font brush arg.bounds.location.x arg.bounds.location.y -- draw the text string
 				)
 			)
 		   
 			arg.DrawFocusRectangle() -- draw the focus rectangle last
 		)
 		
 		on dnListBoxTestRollout open do
 		(
 -- 			dnListBox.drawMode = dnListBox.drawMode.OwnerDrawVariable
 			dnListBox.drawMode = dnListBox.drawMode.OwnerDrawFixed -- fixed seems to be faster than variable, otherwise I can't tell the difference
 			dnListBox.backcolor = lbBackColor
 			dnListBox.SelectionMode = dnListBox.SelectionMode.MultiExtended
 			dnListBox.Items.AddRange ListItems
 		)
 	)
 	createDialog dnListBoxTestRollout width:410 height:420 --pos:[440,85]
 )
 
Old 10 October 2012   #8
Originally Posted by Gravey: i made this code some years ago to test custom text and selection colours in a dotnet listbox. Should be helpful.

Yep.
Excellent examle
__________________
Looking in the right side. [bgaTools]
 
Old 10 October 2012   #9
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 11:12 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.