color on backgroud of combobox panel
Posted
#1
(In Topic #1953)
Trainee

background on combobox
Hello everyone.I'm new to Linux.
I'd like to be able to change the color of the combobox panel. You can change its background using the `background` property, but I haven't found a way to change the background color of the combobox when it's open.
Is this possible in Gambas?
Regards
Posted
Guru


I can see what you want to do. I can't, however, see an easy way to do this. It may be possible by building a new control. What are you aiming to create?
Posted
Trainee

Actually, the control works perfectly for me. I just wanted to change the background and text colors. On the combo box, the background and text can be customized using the `background` and `foreground` properties.
But when you click on the combo box to open it, the panel displays black text on a white background. (I assume this is the default color of my Linux theme.)
My modifications are quite basic. It's mainly to darken the background color slightly when the control receives focus and revert to the original color when it loses focus.
For the combo box, this works perfectly when it's closed, but apparently, you can't change the panel color.
Best regards from France
Eric
Posted
Guru


Best regards from Guernsey, I can see your country on a clear day.
Charlie
Posted
Enthusiast


LAISSLER said
But when you click on the combo box to open it, the panel displays black text on a white background. (I assume this is the default color of my Linux theme.)
Hi,
as Charlie already answered, you can create your own component if you want.
I don't know your skills, but adding these properties to the official combobox doesn't seem particularly complicated, and if you do, you can study the code directly from its author: Benoit Minisini.
A little more complicated is ensuring that the new component doesn't interfere with the original one.
Depending on your Gambas, Master, or Stable, you can navigate to the combobox component. For example, since I have the master, I can download the component directly from here:
comp/src/gb.gui.base/.src/ComboBox · master · Gambas / gambas · GitLab
The component only by clicking the blue button (on the right) that says Code and choosing:
Download directory (I always choose the compressed tarball tar.gz file).
If you choose Download source code, you download the entire Master.
The same applies to any stable version you have, which you'll need to select from the button in the top left.
Let's say you're on GambOS, then you should download the stable version 3.19.6.
On the GitLab page, click the (white) MenuButton on the left and scroll down to version 3.19.6. You'll notice the difference since the last update was a year ago.
Download and unzip the file, extracting it into a folder.
Now, in the Gambas IDE, you need to create a new graphical project called ComboColorTest.
In the browser on the left, in the Sources folder, right-click to create a subfolder called myComponent.
Right-click on the new folder and select Import File from the menu. By navigating to the folder where you unzipped the ComboBox component, you'll import all the files.
Make sure the dialog box shows all the files, and note that you'll need to navigate through several folders before reaching the ComboBox folder.
A window will warn you that the files already exist; ignore it and click OK.
As per the warning, the ComboBox component already exists in Gambas, so you need to rename it. ComboColor can work fine.
If you try to change the name (right-click the class and choose Rename from the menu) of the _ComboBox_Item class, you'll immediately get the "Unknowidentifier:Main" error.
As the warning says, you're missing Main, the Main module.
You'll need to reopen Firefox or your preferred browser and return to gb.gui.base where you downloaded ComboBox to also download the module, which you'll find a little further down.
Open Main.module and you'll see a button with a downward-pointing arrow on the left. If you hover over it, it says download. Click it to also download the module, which you'll add by importing it to the myComponent folder.
Finally, in the folder, after renaming them, in addition to the Main module, there will be the hidden classes _ComboColor_Item, _ComboColor_Selection, the ComboColor class, and the FComboColorPopup form.
Now you need to do a global search to replace ComboColor in the ComboBox code.
Once this is done, all that's left to do is add these two lines of code to the opening code of the FComboColorPopup form (Public Sub Open(aText As String[], aRichText As String[], iIndex As Integer, hCtrl As ComboColor) As Integer) just below the Try gvwPopup.Row = iIndex code:
Code
' --to color the popup
gvwPopup.Background = $hCombo.Background
gvwPopup.Foreground = $hCombo.Foreground
Now, among the tools at the bottom right, under Form, you'll see the ComboColor component added, which you can use like any other control.
I honestly don't know why Benoit Minisini didn't add this feature by default.
I hope I've given you some ideas, perhaps a little too advanced, but if you install Gambas, perhaps on a GambOS virtual machine, you can start using Gambas with a greater understanding of what you're doing, starting with the basics.
I hope you enjoy Gambas as much as I do.
If any steps are unclear, I'm available for clarification.
Posted
Trainee

I will look into this carefully.
Best regards from France
1 guest and 0 members have just viewed this.


