Columbo 1 Posted December 11, 2023 I'm trying to find a way to change the color of the Titlebar and TLabel fonts and TEdit fonts to my own chosen colors. The 'Color ' menu does not give you a lot of choices. A lot of greys and whites but few colors and I don't see any way to add a color such as #562703 or RGB 86,39,11. Is it possible to do this? Thanks Share this post Link to post
corneliusdavid 214 Posted December 11, 2023 For controls like TLabel and TEdit, you can use color constants defined in System.UITypes or specify your own as hex numbers; the TColor type is simply a UInt32 in the range -$7FFFFFFF-1..$7FFFFFFF. For example, both of the following lines set a label's font color to navy: Label1.Font.Color := clNavy; Label1.Font.Color := TColor($800000); The TitleBar is a special case and you have to enable custom properties for it; watch this tutorial video on Creating Custom Title Bars from DelphiCon 2021. Share this post Link to post
Columbo 1 Posted December 11, 2023 Thanks David, Quote The TitleBar is a special case and you have to enable custom properties for it; watch this tutorial video on Creating Custom Title Bars from DelphiCon 2021. I did happen to come across that video and found out how to do it, although again in that video he uses colors from the 'Color' drop down menu. I need to use my own custom color #502F0F. Quote Label1.Font.Color := clNavy; Label1.Font.Color := TColor($800000); So, using your code example, can I just replace the 'TColor($800000); with 'TColor(#502F0F' ? Thanks again. Share this post Link to post
corneliusdavid 214 Posted December 11, 2023 2 minutes ago, Columbo said: So, using your code example, can I just replace the 'TColor($800000); with 'TColor(#502F0F' ? Not with "#" but with a "$". Hex numbers in Delphi are prefixed with $. Label1.Font.Color := TColor($502F0F); Share this post Link to post
Remy Lebeau 1394 Posted December 11, 2023 (edited) 12 hours ago, Columbo said: The 'Color ' menu does not give you a lot of choices. A lot of greys and whites but few colors and I don't see any way to add a color such as #562703 or RGB 86,39,11. Is it possible to do this? Assigning custom colors to properties via code at runtime is trivial, as shown earlier. But if you want to choose custom colors at design-time, that is possible but not trivial, as you have to write your own custom property editor and register it for TColor, overriding the default property editor. See webcolors and custom colors in Delphi's Object Inspector colorpicker at design-time Custom colors in Delphi 7 Edited December 11, 2023 by Remy Lebeau Share this post Link to post
Pat Foley 51 Posted December 11, 2023 Here is a sample using a ColorDialog and ListBox. Note In the IDE you can interact with the colordialog on the form to preload custom colors. The ColorDialog can be to show full with in object inspector. procedure TForm1.Button1Click(Sender: TObject); begin If ColorDialog1.Execute Then Listbox1.Items := ColorDialog1.CustomColors; end; procedure TForm1.ListBox1Click(Sender: TObject); begin if Sender is TListBox then begin var lb := TListBox(Sender); var I := lb.ItemIndex; Color := StrtoInt('$' + lb .Items .ValueFromIndex[I] ); end; end; Share this post Link to post
Columbo 1 Posted December 12, 2023 Thanks guys, I think I've got that now. I guess should do this in another post but my problem now is with a tabbed panel. I created a panel with 2 tabs. I want to load 2 images, one image into each tab. I tried to put a TImage control in each tab but that does not work. Once the TImage control is placed in Tab1, you can no longer switch tabs. If you load and image into the TImage control the same image is displayed in both tabs. I don't have room on my form to create 2 separate panels with separate TImage controls. I have searched all over for a solution but can't find anything on this. Suggestions? Share this post Link to post
Columbo 1 Posted December 12, 2023 I managed to accomplish what I was trying to do by using a TabSheet. It seems to work where the TabPanel would not. I placed a TImage control in each tab and loaded an image in each tab just to test it and it works as I wanted it to. I removed the images since they were just for testing and now I will try to figure out how to load an image into each TabSheet programmatically. Share this post Link to post
Serge_G 87 Posted December 12, 2023 (edited) For each question (first one) I suggest you to indicate Delphi version. 5 hours ago, Columbo said: I created a panel with 2 tabs. use a TPageControl linked to a TImageList. You can change for each tab the imageindex property (-1 to "hide" image) If Delphi 11, for the Font Color problems, with new versions you have to take care of StyleElements property, if you have set some appearance (style) to the project and don't remove seFont from the array then color you set at runtime should not be taken into account. Here, appearance is set to "Windows10 blue", button1.click code Label1.font.Color:=clred; is inefficient except if you set Label1.StyleElements:=Label1.StyleElements-[seFont] Edited December 12, 2023 by Serge_G Share this post Link to post
Columbo 1 Posted December 12, 2023 Thanks Serge, I am using Delphi 11 Community. I didn't do anything with StyleElements because I was not aware of what that does. What I used was lblName.Font.Color := TColor(#575). When I run the program it works ok. As for the Tabs, I don't want to place an image in them permanently. I have a database with 115 records and each record has 2 images associated with it. When a record is selected I want it to display the associated images, one in each tab. I need to know how to place these images into the tabs programmatically. I have searched the internet and I see lots of discussion on placing images into tabs permanently using TImageList but nothing on how to do it at run time. Share this post Link to post
corneliusdavid 214 Posted December 12, 2023 1 hour ago, Columbo said: I need to know how to place these images into the tabs programmatically Look at the help for TImageList.Add. There's a code sample that shows how to load a selected image file from disk. You can extend that to your database by either saving out the image to a temporary file or streaming it directly to a TImage. Share this post Link to post
corneliusdavid 214 Posted December 12, 2023 @Columbo, I had a few minutes and explored this technique of loading a TImageList dynamically a little more for my own curiosity and wrote a test program. The attached project loads a memory table with some local bitmaps, then as you scroll through the table, it pulls the image out of the table and clears/refreshes the image list which is associated with the page control. It should get you close to what you want. ImageListLoadTest.zip Share this post Link to post