Announcement

Collapse
No announcement yet.

Textfelder färben

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Textfelder färben

    Hallo Gemeinde,

    ich möchte in einer Form das Textfeld, dass den Fokus erhält, einfärben (ähnlich SAP) und beim Verlassen wieder "entfärben". Da die Form jedoch sehr viele Textfelder hat und das Programm viele Forms, wäre eine Routine genial, die das OnEnter und OnExit Event eines jeden Textfeldes abfängt und dann entsprechend färbt.

    Vielen Dank fürs "Mitbrainen"

    Gruß
    Uwe

  • #2
    Hallo Uwe,
    das geht am Besten mit Screen:
    Dazu musst du irgendwo 2 Properties oder Variablen zum Speichern des letzten aktiven und gerade aktiven Controls anlegen.
    <CODE>
    private
    FPreviousControl: TWinControl;
    FActiveControl: TWinControl;
    ...
    // das nächste evtll. im Constructor
    Screen.OnActiveControlChange := doActiveControlChange;
    ...
    procedure TMainForm.doActiveControlChange(Sender: TObject);
    begin
    ...
    letztes Control entfärben
    FActiveControl := screen.ActiveControl;
    neues Control einfärben
    ...
    end;
    </CODE>
    Das Merken des letzten Control etc. überlasse ich dir.
    Oder Komponenten von Developer Express, die können das von Haus aus...
    <BR>Gruß Fran

    Comment


    • #3
      Hallo Frank,

      aus der Hilfe habe ich folgendes Beispiel:

      procedure TfmMain.ColorControl(Sender: TObject);
      var
      i : Integer;
      begin
      for I:= 0 to ControlCount -1 do
      begin
      if Controls[i] is TEdit then
      begin
      if Controls[i] as TEdit.Focused then
      Controls[i] as TEdit.Color := $009BF5FD
      else
      Controls[i] as TEdit.Color:= clWhite;
      end;
      end;
      end;

      procedure TfmMain.FormCreate(Sender: TObject);
      begin
      Screen.OnActiveControlChange := ColorControl;
      end;

      In einem beim Programmstart erzeugten Formular funktioniert das auch bestens. Mein Formular hingegen ist ein MDI-Formular. Sobald aus dem Hauptformular das MDI-Formular erzeugt wird, bekomme ich eine Zugriffsverletzung. Habe schon alles mögliche versucht und die Routine an allen möglichen Stellen platziert. Komme jedoch zu keinem Ergebnis. Hast Du eine Idee?

      Gruß
      Uw

      Comment


      • #4
        Hallo Uwe,
        ich hab mal schnell eine Klasse geschrieben. Probier es mal aus.
        <CODE>
        unit EditColorHandler;<BR>
        interface
        Uses Forms, Classes, Controls, Graphics, StdCtrls;<BR>
        Const
        _ActiveColor = $009BF5FD;
        _DefaultColor = clWhite;<BR>
        type
        TEditColorHandler = class(TObject)
        private
        FActiveControl: TWinControl;
        FActive: Boolean;
        procedure SetActive(const Value: Boolean);
        public
        procedure doActiveControlChange(Sender: TObject);
        property Active: Boolean read FActive write SetActive;
        end;<BR>
        Var
        AppEditColorHandler: TEditColorHandler;<BR>
        implementation<BR>
        procedure TEditColorHandler.doActiveControlChange(Sender: TObject);
        begin
        if Assigned(FActiveControl) and FActiveControl.HandleAllocated and
        (FActiveControl is TEdit) then
        TEdit(FActiveControl).Color := _DefaultColor;<BR>
        FActiveControl := Screen.ActiveControl;<BR>
        if FActiveControl is TEdit then
        TEdit(FActiveControl).Color := _ActiveColor;<BR>
        end;<BR>
        procedure TEditColorHandler.SetActive(const Value: Boolean);
        begin
        if FActive <> Value then
        begin
        FActive := Value;
        if FActive then
        Screen.OnActiveControlChange := doActiveControlChange
        else
        Screen.OnActiveControlChange := nil;
        end;
        end;<BR>
        initialization
        AppEditColorHandler := TEditColorHandler.Create;<BR>
        finalization
        AppEditColorHandler.Free;<BR>
        end.
        </CODE>
        die Unit in Uses des MainForm und an einer günstigen Stelle:
        <CODE>
        AppEditColorHandler.Active := True;
        </CODE>
        Fran

        Comment


        • #5
          Hi Frank,

          absolut genial!! Vielen Dank. Hat auf Anhieb funktioniert.

          Gruß
          Uw

          Comment

          Working...
          X