May 04, 2024, 12:20:25 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Tree view control colour

Started by Andy, April 17, 2016, 05:40:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

I'm just going through some of my older code, and whilst looking at my registry viewer / editor I was wondering if it is possible to change the colour of an intersted item in the tree view.

In other words, I have the main item (root), and then many child items under it in a tree view control.

I would like to have the root entry and the child entries appear something like a yellow background and black for text - so they look more like folders that catch your eye.

Anyone done this? or even is it possible?

Thanks,
Andy.

:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

Tried SETCONTROLCOLOR ??

(see controldemo.iwb in the IWB examples directory).
Support Amateur Radio  -  Have a ham  for dinner!

Andy

Egil,

Thanks for the idea, I tried that but doesn't work for me - but nice suggestion.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

April 17, 2016, 06:30:04 AM #3 Last Edit: April 17, 2016, 06:32:39 AM by Egil
I know it is possible, because I use a freeware program where I can change colors in a treeview control and text at will.
(See attached picture)
And Fletchie use it in the helpfile for his control library.
Support Amateur Radio  -  Have a ham  for dinner!

Andy

April 17, 2016, 06:36:08 AM #4 Last Edit: April 17, 2016, 06:38:21 AM by Andy
Egil,

You're on the right lines, but the example you provided shows the whole of the background in colour, I'm just trying to find a way just to colour the individual entries, such as "General", "ALOGRITHMS" etc.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

Andy,

Have not tried this myself, but beleive this is what you want.
Support Amateur Radio  -  Have a ham  for dinner!

Andy

Egil,

Something like that would be perfect - just something visual so it catches your eye.

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

Andy,

Have experimented a little, but all I managed was changing colors for the whole control, or no change at all.
But running out of time here... My plane departs at 2100 so have to leave soon (1900 now). Posting the code I have been playing with.

Good luck!


'
' Code copied from IBasicPro CodeArchive downloaded from http://www.codingmonkeys.com/
' modified to set colors to the control by Egil
'

Window Win
OpenWindow Win,0,0,400,400,0,0,"Doubleclick items to list the full path",&Main
CenterWindow Win

Int X,Y
GetClientSize Win,X,Y,X,Y
Control Win,@TreeView,"",8,8,X-16,Y-40,@TvsHasLines|@TvsLinesAtRoot|@TVSHASBUTTONS,1
'Control Win,@TreeView,"",8,8,100,100,@TVSHASBUTTONS,1


' Setting Treeview Control Colors
'------------------------------------------------------------------------------------------
CONST TV_FIRST = 0x1100
CONST TVM_SETBKCOLOR = (TV_FIRST + 29)
CONST TVM_SETTEXTCOLOR = (TV_FIRST + 30)
    sendmessage Win,TVM_SETBKCOLOR,0,rgb(255,255,0),1
    sendmessage Win,TVM_SETTEXTCOLOR,0,rgb(0,255,255),1
'------------------------------------------------------------------------------------------


Uint r0,c00,c01,c011,c010,c0100,c02,c020
Uint r1,c10,c11,c12
r0=TvwInsertItem(Win,1,"File..",0)
   c00=TvwInsertItem(Win,1,"Save",r0)
   c01=TvwInsertItem(Win,1,"Load..",r0)
      c010=TvwInsertItem(Win,1,"C:..",c01)
         c0100=TvwInsertItem(Win,1,"My Documents",c010)
      c011=TvwInsertItem(Win,1,"E:",c01)
   c02=TvwInsertItem(Win,1,"Exit..",r0)
      c020=TvwInsertItem(Win,1,"Select To Quit",c02)
r1=TvwInsertItem(Win,1,"Edit..",r1)
   c10=TvwInsertItem(Win,1,"Cut",r1)
   c11=TvwInsertItem(Win,1,"Copy",r1)
   c12=TvwInsertItem(Win,1,"Paste",r1)

WaitUntil Win=0
CloseWindow Win
End

Sub Main(),int
   String S,ItemText[10]
   Uint I
   Select @Message
      Case @IdCloseWindow
         CloseWindow Win
      Case @IdControl
         Select @ControlId
            Case 1
               Select @NotifyCode
                  Case @NmDblClk
                     TvwGetItemText(Win,1,ItemText,255)
                     I=0:S=""
                     While ItemText[I]<>""
                        S=ItemText[I]+"\\"+S
                        I++
                     EndWhile
                     Move(Win,16,Y-32)
                     Print Win,"Item Path: "+S+String$(48," ")
                     If Instr(S,"Quit")
                        CloseWindow Win
                     EndIf
               EndSelect
         EndSelect
   EndSelect
   Return 0
EndSub

Sub TvwInsertItem(Win:Window,Id:Uint,ItemText:String,Parent:Uint),Uint
'Inserts an item and sets the item data equal to the parents handle to be able
' to get the full item path using TvwGetItemText():
   Uint Hnd
   Hnd=TvInsertItem(Win,Id,ItemText,Parent)
   TvSetItemData(win,Id,Hnd,Parent)
   Return Hnd
EndSub


Sub TvwGetItemText(Win:Window,Id:Uint,ItemText[]:String,TextLen:Uint)
'Returns the full item path to the item if it is stored using TvwInsertItem():
   Uint Hnd,I,J
   String Tmp
   Hnd=tvGetSelectedItem(Win,Id)
   I=0
   Do
      tvGetItemText(Win,Id,Hnd,ItemText[I],255)
      Hnd=tvGetItemData(Win,Id,Hnd)
      I++
      ItemText[I]=""
   Until Hnd=0
   'Reverse the array string order:
   J=0
   Do
      Tmp=ItemText[I-1]
      Itemtext[I-1]=ItemText[J]
      ItemText[J]=Tmp
      I--:J++
   Until I=0
   Return
EndSub


Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

Andy
Play with this and see if you can get something you like out of it maybe
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

Larry,

That's exactly what I was looking for, I will have a play around with this example.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy


Here is a screenshot of my registry viewer / editor in colour.

Not decided these are the final colours yet, but you can see it brings the program to life.

Thanks Larry!

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

LarryMc

you need to add a manifest file to your program so your buttons will look better.
but yes, the colors do make it stand out
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library