Einzelnen Beitrag anzeigen

Pfoto

Registriert seit: 26. Aug 2005
Ort: Daun
541 Beiträge
 
Turbo Delphi für Win32
 
#9

Re: Bei OnMouseOver Hilfe zu Eintrag in TChecklistBox anzeig

  Alt 24. Jan 2007, 11:45
Hallo nochmal,

also hier ist mein Code, eben getestet:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TItemData = class
  private
    fInfoString: string;
  public
    property InfoString: string read fInfoString;
    constructor Create(aInfoString: string);
  end;

  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    lblItemData: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private-Deklarationen } 
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  { Einfach mal ein paar sinnlose Einträge einfügen }
  for i:= 0 to 10 do
    ListBox1.Items.AddObject('Eintrag Nr. ' + inttostr(i), TItemData.Create('Daten zu Eintrag Nr. ' + inttostr(i)));
end;

{ TItemData }

constructor TItemData.Create(aInfoString: string);
begin
  inherited Create;
  fInfoString:= aInfoString;
end;

procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  Index: integer;
begin
  with TListbox(Sender) do
  begin
    Index:= ItemAtPos(Point(x,y), true);
    ShowHint:= Index <> -1;
    If (Index <> -1) then
      Hint:= TItemData(Items.Objects[Index]).InfoString;
  end;
end;

end.

Natürlich könnte man das Ganze noch etwas perfektionieren, indem z.B.
der Hint schneller oder länger angezeigt wird.
Das kann man ja dann nach Wunsch einstellen.

Gruß

Pfoto
Jürgen Höfs
  Mit Zitat antworten Zitat