CustomEdit: How do you set the Font Color? lazarus / 31-LCL ---------------------------------------------------------------------- Aruna · 2024-09-26 02:16 Hi, I’ve created a custom text input box that functions correctly, but I’m running into an issue with setting the text color. When I attempt to set the color programmatically, it doesn’t take effect. However, if I set the color in the Object Inspector for the Main Form, it applies as expected. How can I fix this? I’ve attached the source code in a zip file, and the screenshot shows the login form where I’m trying to change the text color. ---------------------------------------------------------------------- Thaddy · 2024-09-26 04:42 You just need to call invalidate after you change the color in code. That will force a repaint. ---------------------------------------------------------------------- jeremiah · 2024-09-26 04:44 On button.click set font color: MyEdit.Font.Color := clred;  // Background color peace... ---------------------------------------------------------------------- TRon · 2024-09-26 05:37 changing the color (alone) is not going to work for gtk and certain themes in use. issue 38516 having said that: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomEdit2.Paint;begin  // Draw the TEdit background color  Canvas.Brush.Color := $00EF3F0E;// Canvas.Brush.Color := $0063D0E5;  Canvas.FillRect(ClientRect);   // Draw the TEdit Border  Canvas.Pen.Color:=clYellow;  Canvas.Pen.Width:=1;  Canvas.Rectangle(cl ientrect.Left-10,clientrect.Top- 10,clientrect.Right,clientrect.Bottom);   // Draw the background image if assigned  if Assigned(FBackgroundImage.Graphic) then    Canvas.Draw(0, 0, FBackgroundImage.Graphic);   // Draw the text  Form1.Font.Color:=clBlack;//  Canvas.Font.Color:=clWhite;  Canvas.Font.Color:=clRed;  Canvas.Font.Assign(Self.Font);  // Use the font of the control  Canvas.TextOut(15, (Height - Canvas.TextHeight(FText)) div 2, FText);  // Center text vertically  invalidate;end;  this ? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomEdit2.Paint;begin  // Draw the TEdit background color  Canvas.Brush.Color := FBackgroundColor;  Canvas.FillRect(ClientRect);   // Draw the TEdit Border  Canvas.Pen.Color:=clYellow;  Canvas.Pen.Width:=1;  Canvas.Rectangle(cl ientrect.Left-10,clientrect.Top- 10,clientrect.Right,clientrect.Bottom);   // Draw the background image if assigned  if Assigned(FBackgroundImage.Graphic) then    Canvas.Draw(0, 0, FBackgroundImage.Graphic);   // Draw the text  Self.Font.Color := clRed;  // <-- or set it in mainform.myedit.font.color (as per jeremiah)  Canvas.Font.Assign(Self.Font);  // Use the font of the control  Canvas.Font.Color:=clRed; // <-- or set the canvas font color after the assign  Canvas.TextOut(15, (Height - Canvas.TextHeight(FText)) div 2, FText);  // Center text vertically  invalidate;end;