Change colour of text in treeview sub node

Just starting out? Need help? Post your questions and find answers here.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Change colour of text in treeview sub node

Post 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
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: Change colour of text in treeview sub node

Post 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:
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Change colour of text in treeview sub node

Post 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. :)
malleo, caput, bang. Ego, comprehendunt in tempore
hazard
New User
New User
Posts: 7
Joined: Sat Apr 14, 2012 5:40 pm

Re: Change colour of text in treeview sub node

Post by hazard »

You need to use custom draw (or owner draw) techniques on Windows. A search through the forums should provide some examples.
ebs
Enthusiast
Enthusiast
Posts: 557
Joined: Fri Apr 25, 2003 11:08 pm

Re: Change colour of text in treeview sub node

Post 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
hazard
New User
New User
Posts: 7
Joined: Sat Apr 14, 2012 5:40 pm

Re: Change colour of text in treeview sub node

Post by hazard »

He wants multiple colors on the same line! :wink:
BorisTheOld
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Apr 24, 2012 5:08 pm
Location: Ontario, Canada

Re: Change colour of text in treeview sub node

Post 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.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: Change colour of text in treeview sub node

Post 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 ...
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Change colour of text in treeview sub node

Post 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
malleo, caput, bang. Ego, comprehendunt in tempore
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Re: Change colour of text in treeview sub node

Post 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 ... ;-)
Post Reply