Foreground Fileview [SOLVED]
Posted
#1
(In Topic #1035)
Trainee
I am using a fileview and I would need to have a different foreground color, for example, if the file name contains "Picture056".
Is this possible? :?:
Posted
Guru

Can you tell us exactly what you are trying to achieve. I can't find a setting to change a background of a single FileView icon, but there may well be another way.
Posted
Trainee
I would like to change the font color of one or several items in the fileview.
For my example:
In my application, I save a "note" on an image and I would like the text color of the element to change. I can do it with the foreground parameter, but it modifies everything (here in red).
Sorry for my English - I am French.
Code (gambas)
Posted
Guru

IconView has Keys and the items have a .RichText property so you can set <font color=red>.
FileView uses an IconView to show it's contents so you can access it like this…
Code (gambas)
- ' get the IconView control inside the FileView
- ' if file name has a b in it then set its text red
- IView[s].RichText = "<font color=red>" & IView[s].Text & "</font>"
That will show every file with a b in it as red text.
Posted
Regular

BruceSteers said
Bravo ! <EMOJI seq="1f44d" tseq="1f44d">👍</EMOJI>
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Guru

vuott said
Why thank you kind sir
So let's take it a step further…
The above code only works if the FileView is not in "Detailed" view mode as detailed mode uses a ColumnView not an IconView.
So below is the test code I just made
The Form has a FileView a TextBox and a ComboBox
The combobox changes the View mode
With the TextBox you can provide a pcre text pattern and names matching the pattern will show red. Ie. IMG_*
it will work in all FileView View modes
Code (gambas)
- ComboBox1.List = ["Normal", "Compact", "Detailed", "Preview"]
- MakeFileViewTextRed(TextBox1.Text)
- MakeFileViewTextRed(TextBox1.Text)
- ' Make FileView1 text red or not depending on the pcre Pattern
- IView[s].RichText = "<font color=red>" & IView[s].Text & "</font>"
- IView[s].RichText = IView[s].Text
- IView.Refresh
- CView[s].Foreground = Color.Red
- CView.Refresh
Posted
Guru

cogier said
Hi toto96 and welcome to the forum.
Can you tell us exactly what you are trying to achieve. I can't find a setting to change a background of a single FileView icon, but there may well be another way.
With Gambas there is very often another way
Let me explain how i figured out the above posted method…
1. I added this simple test code to my Form_Open
2. So I then tried this code..
I have access to the IconView and the ColumnView of the FileView control and can use their properties for customization.
I use this method a lot to find the way to private controls within controls for tweaks.
Happy coding
Posted
Guru

toto96 said
Hi
I would like to change the font color of one or several items in the fileview.
For my example:
In my application, I save a "note" on an image and I would like the text color of the element to change. I can do it with the foreground parameter, but it modifies everything (here in red).
Sorry for my English - I am French.Code (gambas)
You should be able to use the above method to access the IconView inside the FileView and set individual items of choice.
But watch out for the Key names with the IconView not quite matching the text. (mine were prefixed with 1)
Ie.
If the file name is IMG_4591.jpg
The ColumView Key name was CView["IMG_4591.jpg"]
The IconView Key name was IView["1IMG_4591.jpg"]
Best of luck
Posted
Guru

Here is code that sets individual items.
it uses a String[] array called $aMarkedFiles
Any items added to this list show red while others show default colour
I've attached the project so you can test it out.
it has 2 buttons "Mark file" and "Unmark file" that toggle items having red text for you.
Hopefully you can use it for your needs
Code (gambas)
- ' Gambas class file
- ComboBox1.List = ["Normal", "Compact", "Detailed", "Preview"]
- MakeFileViewTextRed
- ' go through the FileView contents setting any items that are in the $aMarkedFiles array to red
- IView[s].RichText = "<font color=red>" & IView[s].Text & "</font>"
- IView[s].RichText = IView[s].Text
- IView.Refresh
- CView[s].Foreground = Color.Red
- CView.Refresh
- FileView1_Click
- $aMarkedFiles.Add(FileView1.Current)
- MakeFileViewTextRed
- $aMarkedFiles.Remove($aMarkedFiles.Find(FileView1.Current))
- MakeFileViewTextRed
- btnUnmark.Enabled = bMarked
Posted
Regular

Why ?
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Guru

vuott said
No files appear in the FileView Control.
Why ?
I have no idea.
You can see in form open…
FileView1.Dir = User.Home
It populates just fine here with files in $HOME !
Posted
Regular

ok.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Trainee
Thanks to everyone for your help
Posted
Guru

toto96 said
A big thank you to BruceSteers, it works perfectly.
Thanks to everyone for your help
No worries, happy to help.
My advice to help you experiment with making controls do things beyond the normal would be this..
* See if the control exists in the components gb.form or gb.gui.base and examine it's source code.
If you do not have the source downloaded it can be viewed here..
comp/src/gb.form · master · Gambas / gambas · GitLab
comp/src/gb.gui.base · master · Gambas / gambas · GitLab
Examining the source of the custom gambas controls can really help see what can and cannot be done.
* use the "Print object.Children[x]" trick i mentioned in the previous post to find the Children/types and the path to the internal control you want to tweak.
* use the wiki to see what properties/methods the controls have to get what you want (Ie. like using .RichText in place of .Foreground for text colour)
Also be aware things like this can possibly break at some point if the main component changes. (i think it is rare)
For example if something changes in the FileView control that adds an Object/Panel before the others, then the Panel we want may not be Children[0] anymore.
1 guest and 0 members have just viewed this.




