Page 1 of 1

Change colour of text in treeview sub node

Posted: Sun Apr 22, 2012 1:33 am
by Zebuddi123
Hi to All

How to have two colour`s on the same line ie string is "foobar foobar --- myfoobar" ---- the foobar foobar to stay as system colours but i want the
myfoobar to be red.

so in the subnode ( "foobar foobar --- myfoobar" ) like this

any help much appreciated

Zebuddi. :D

Re: Change colour of text in treeview sub node

Posted: Mon Apr 23, 2012 2:31 pm
by charvista
Hi Zebuddi, hope this helps you.

Code: Select all

Win=OpenWindow(#PB_Any,0,0,800,600,"Template",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)

F1=LoadFont(#PB_Any,"Microsoft Sans Serif",8)

V.s="foobar foobar --- myfoobar"
V1.s=Left(V,18)
V2.s=Mid(V,19)

StartDrawing(WindowOutput(Win))
DrawingFont(FontID(F1))
WidthV1=TextWidth(V1)
StopDrawing()


T1=TextGadget(#PB_Any,10,10,WidthV1,20,V1)
SetGadgetFont(T1,FontID(F1))
SetGadgetColor(T1,#PB_Gadget_FrontColor,$000000)

T2=TextGadget(#PB_Any,10+WidthV1,10,200,20,V2)
SetGadgetFont(T1,FontID(F1))
SetGadgetColor(T2,#PB_Gadget_FrontColor,$0000FF)


Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
:wink:

Re: Change colour of text in treeview sub node

Posted: Mon Apr 23, 2012 5:54 pm
by Zebuddi123
@ chavista

Hi and thanks for the reply. Its not what i was looking to do, the problem is i am passing a string q$ to addgadgetitem() which is a treeviewgadget().

now q$ is made from several strings, the initial string say foobar systemcolour and the next added string to q$ would be a colour of my choice as you tried to do
the problem is i have to pass the whole string to addgadgetitem() (else the string would be placed the next element down ) so the whole string is changed by

Code: Select all

SetGadgetColor(#Tree_2,#PB_Gadget_FrontColor,$D65011)
. so it looks like i would have to play directly with memory to do as im looking for!! but i`m not that advanced yet.

But thank you for the reply and trying

Zebuddi. :)

Re: Change colour of text in treeview sub node

Posted: Mon Apr 23, 2012 6:40 pm
by hazard
You need to use custom draw (or owner draw) techniques on Windows. A search through the forums should provide some examples.

Re: Change colour of text in treeview sub node

Posted: Tue Apr 24, 2012 4:15 pm
by ebs
Zebuddi123,

Can't you just use SetGadgetItemColor(#Gadget, Item, ColorType, Color [, Column]) ?
I've used it to color nodes on a TreeGadget lots of times.

Regards,
Eric

Re: Change colour of text in treeview sub node

Posted: Tue Apr 24, 2012 5:11 pm
by hazard
He wants multiple colors on the same line! :wink:

Re: Change colour of text in treeview sub node

Posted: Tue Apr 24, 2012 5:48 pm
by BorisTheOld
Can a number of text gadgets be placed on the line? The line text could then be split between the text gadgets and coloured appropriately.

Just a thought.

Re: Change colour of text in treeview sub node

Posted: Tue Apr 24, 2012 10:36 pm
by USCode
I don't believe it's possible with PB commands to mix colors on the same line in a treeview, you can only set the front and back colors with SetGadgetItemColor().
However one of the Win API gurus will probably have a solution for you ...

Re: Change colour of text in treeview sub node

Posted: Wed Apr 25, 2012 1:30 am
by Zebuddi123
Thanks for the responses. as UScode points out its not possible with PB commands front or backcolor only. basically ive written my self a tool not finished yet but working, it reads from the PB include folder all the includes and indentifies all the files and procedures in treeview like i said its not fully finished yet but im gonna post it in announcements for anyone who wants to try it.

I`m no programming Guru just having fun playing with ideas and making useful stuff for myself. constructive critisism very welcome, but its a great community and i wouldnt expect anything less!!!


Zebuddi. :D

Re: Change colour of text in treeview sub node

Posted: Wed Apr 25, 2012 2:12 am
by USCode
Not sure what you're trying to achieve but perhaps as the poor man's solution, instead of highlighting in red you could just capitalize the text you want emphasized?
"foobar foobar --- MYFOOBAR"

Or wrap it in parentheses:
"foobar foobar --- (myfoobar)"

etc. etc.

I know, lame suggestions, but sometimes you gotta do what you gotta do ... ;-)