Announcement

Collapse
No announcement yet.

Mehr Übersicht für Endbenutzer

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

  • Mehr Übersicht für Endbenutzer

    Hallo Leute,
    vor einiger Zeit hatte ich mal gefragt ob man eine TListBox-Komponente so umbiegen kann, dass, wenn der Focus die Komponente verlässt, sich der/die markierten/n Items umfärben.
    Nach langen probieren, und einigen „Denk“Pausen hat es doch funktioniert.
    (ps: Dank an Christian Wende für sein Beispiel mit DoEnter und DoExit, .. wäre daran fast verzweifelt.. thanks)

    Hier nun der Code:

    ********************** ListBoxNeu.h ****************************

    //---------------------------------------------------------------

    #ifndef ListBoxNeuH

    #define ListBoxNeuH

    //---------------------------------------------------------------

    #include <SysUtils.hpp>

    #include <Controls.hpp>

    #include <Classes.hpp>

    #include <Forms.hpp>

    #include <StdCtrls.hpp>

    //---------------------------------------------------------------

    class PACKAGE TMyListBox : public TListBox

    {

    private:

    TColor ColorSelNoF;

    TColor ColorSelText;

    protected:

    DYNAMIC void __fastcall DoEnter();

    DYNAMIC void __fastcall DoExit();

    public:

    __fastcall TMyListBox(TComponent* Owner);

    __published:

    __property TColor ColorBgrdNoF = {read=ColorSelNoF, write=ColorSelNoF, default=clSilver};

    __property TColor ColorTextNoF = {read=ColorSelText, write=ColorSelText, default=clWhite};

    };

    //---------------------------------------------------------------

    #endif

    ******* ENDE *************** ListBoxNeu.h ****************************

    ********************** ListBoxNeu.cpp ****************************

    //-------------------------------------------------------------------------
    --

    #include <vcl.h>

    #pragma hdrstop

    #include "ListBoxNeu.h"

    #pragma package(smart_init)

    //-------------------------------------------------------------------------
    --

    // ValidCtrCheck wird benutzt, um sicherzustellen, daß die erzeugten
    Komponenten

    // keine rein virtuellen Funktionen besitzen.

    //

    static inline void ValidCtrCheck(TMyListBox *)

    {

    new TMyListBox(NULL);

    }

    //-------------------------------------------------------------------------
    --

    __fastcall TMyListBox::TMyListBox(TComponent* Owner)

    : TListBox(Owner)

    {

    ColorSelNoF = clSilver;

    ColorSelText = clWhite;

    }

    //-------------------------------------------------------------------------
    --

    void __fastcall TMyListBox:oEnter()

    {

    TRect Rect;

    for (int i = 0; i < Items->Count; i++)

    {

    if (Selected[i])

    {

    Rect = ItemRect(i);

    Canvas->Brush->Color = clHighlight;

    Canvas->FillRect(ItemRect(i));

    Canvas->Font = Font;

    Canvas->Font->Color = clWhite;

    Canvas->TextOut(Rect.Left + 2, Rect.Top,Items->Strings[i]);

    }

    }

    TListBox:oEnter();

    }

    //-------------------------------------------------------------------------
    --

    void __fastcall TMyListBox:oExit()

    {

    TRect Rect;

    for (int i = 0; i < Items->Count; i++)

    {

    if (Selected[i])

    {

    Rect = ItemRect(i);

    Canvas->Brush->Color = ColorSelNoF;

    Canvas->FillRect(ItemRect(i));

    Canvas->Font = Font;

    Canvas->Font->Color = ColorSelText;

    Canvas->TextOut(Rect.Left+2, Rect.Top,Items->Strings[i]);

    }

    }

    TListBox:oExit();

    }

    //-------------------------------------------------------------------------
    --

    namespace Listboxneu

    {

    void __fastcall PACKAGE Register()

    {

    TComponentClass classes[1] = {__classid(TMyListBox)};

    RegisterComponents("Meine", classes, 0);

    }

    }

    ************ ENDE ********** ListBoxNeu.cpp ****************************

    Bis dann Mario
Working...
X