Einzelnen Beitrag anzeigen

Benutzerbild von Sven Janssen
Sven Janssen

Registriert seit: 22. Jun 2004
Ort: Mayen
187 Beiträge
 
Delphi 4 Professional
 
#9

Re: Focus von Felder besser hervorheben (global)

  Alt 16. Jul 2004, 08:21
Nachstehende Procedure habe ich in eine include Datei geschrieben, die bei uns eh immer in der ersten Form1 mit eingebunden wird. Grundvoraussetzung natürlich, das diese immer den Namen Form1 behält.
Code:
procedure TForm1.controlCheck(sender:TObject);
var i,j:integer;
begin
    if getglobalpara('allgemein.ini','Allgemein','Highlighting',TRUE) = FALSE then exit;
    for i:=0 to screen.CustomFormCount-1 do begin
        for j:=0 to screen.CustomForms[i].ComponentCount-1 do begin
            if (screen.CustomForms[i].name = fieldFormNameBevorGetFocus) and
                (screen.CustomForms[i].Components[j].name = fieldNameBevorGetFocus) then begin
                if (screen.CustomForms[i].Components[j] is TEdit) then begin
                    (screen.CustomForms[i].Components[j] as TEdit).color:=fieldColorBackgroundBevorGetFocus;
                    (screen.CustomForms[i].Components[j] as TEdit).font.color:=fieldColorTextBevorGetFocus;
                end;
                if (screen.CustomForms[i].Components[j] is TDBedit) then begin
                    (screen.CustomForms[i].Components[j] as TDBedit).color:=fieldColorBackgroundBevorGetFocus;
                    (screen.CustomForms[i].Components[j] as TDBedit).font.color:=fieldColorTextBevorGetFocus;
                end;                        
            end;
        end;
    end;
    if (screen.ActiveControl is TDBEdit) then begin
        fieldColorBackgroundBevorGetFocus:=(screen.ActiveControl as TDBEdit).color;
        fieldColorTextBevorGetFocus:=(screen.ActiveControl as TDBEdit).font.color;
        fieldNameBevorGetFocus:=screen.ActiveControl.name;
        fieldFormNameBevorGetFocus:=screen.ActiveCustomForm.name;
        (screen.ActiveControl as TDBEdit).color:=clInfoBk;
        (screen.ActiveControl as TDBEdit).font.color:=clinfotext;
    end;
    if (screen.ActiveControl is TEdit) then begin
        fieldColorBackgroundBevorGetFocus:=(screen.ActiveControl as TEdit).color;
        fieldColorTextBevorGetFocus:=(screen.ActiveControl as TEdit).font.color;
        fieldNameBevorGetFocus:=screen.ActiveControl.name;
        fieldFormNameBevorGetFocus:=screen.ActiveCustomForm.name;
        (screen.ActiveControl as TEdit).color:=clInfoBk;
        (screen.ActiveControl as TEdit).font.color:=clinfotext;
    end;
   
end;
Ins Formcreate der ersten Form muss folgende Zeile hinzugefügt werden.
Code:
screen.OnActiveControlChange := form1.controlCheck;
Die nachfolgeden Variablen sind in einer Unit die ebenfalls immer mit eingebunden wird.
Code:
    fieldColorBackgroundBevorGetFocus,
    fieldColorTextBevorGetFocus:TColor;
    fieldNameBevorGetFocus,fieldFormNameBevorGetFocus:string;
Die Procedure kann man natürlich nun noch um weitere Komponenten erweitern.

Sven
  Mit Zitat antworten Zitat