0

I'm not able to change DBEdit background color at runtime. If DbEdit styleElements are enabled ([seFont,seClient,seBorder]) DBEditName.Color:=clRed (for example) not working at all. Instead if styleElements=[] DBEditName.Color:=clRed changes only the DBEdit border (see image below). but I'd like a full background color. How can i achieve that?

EDIT

The problem arises when DBEdit Datasource Field is NUMERIC (content is aligned right) and Application has a not-default style applied (no Windows style)

enter image description here

user1709805
  • 2,028
  • 3
  • 19
  • 26
  • Could you include your Delphi version tag into your question ? I cannot reproduce what you described in Delphi XE3. Btw. if you keep included all the style elements, the control is styled by the selected style, so it's correct that you can't change the color. You'd need to exclude the `seClient` element. But then it works as expected (in Delphi XE3). – TLama Feb 24 '14 at 09:05
  • sorry, you're right! I'm using XE5 – user1709805 Feb 24 '14 at 09:13
  • with styleElements=[] only the border is painted. – user1709805 Feb 24 '14 at 09:14

1 Answers1

0

Here's a solution, hope it helps.

DFM:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 300
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DBEdit1: TDBEdit
    Left = 72
    Top = 72
    Width = 121
    Height = 21
    TabOrder = 0
    StyleElements = [seFont, seBorder]
  end
  object Button1: TButton
    Left = 144
    Top = 136
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
end

PAS:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Mask, Vcl.DBCtrls;

type
  TForm1 = class(TForm)
    DBEdit1: TDBEdit;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  DBEdit1.Color := clred;
end;

end.
Filipe.Fonseca
  • 321
  • 2
  • 14