Autor Beitrag
admiralkirk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 16:27 
Ich habe ein TImage, das als button dient. Jetzt soll das TImage wenn die maus drüber fährt das bild wechseln.
Es gibt ja die TImage MouseEnter und - Leave funktionen.
z.B. könnte man bei MouseEnter das 2. bild aus einer TImageList laden und bei MouseLeave zurücksetzen...
Bloß ich bekomme es nicht hin und habe bei google im Foren etc, nur schnipsel gefunden zum verändern von panel farben etc
Könnte mir jmd das ganze an einem Code erklären?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
type
  TLabelEx = class(TLabel)
  private
    fOnMouseEnter: TNotifyEvent;
    fOnMouseLeave: TNotifyEvent;
    procedure cmMouseEnter(var Msg: TMsg); message cm_MouseEnter;
    procedure cmMouseLeave(var Msg: TMsg); message cm_MouseLeave;
  public
    property OnMouseEnter: TNotifyEvent read fOnMouseEnter write fOnMouseEnter;
    property OnMouseLeave: TNotifyEvent read fOnMouseLeave write fOnMouseLeave;
  end;

procedure TLabelEx.cmMouseEnter(var Msg: TMsg);
begin
if Assigned(fOnMouseEnter) then
  fOnMouseEnter(self);
end;

procedure TLabelEx.cmMouseLeave(var Msg: TMsg);
begin
if Assigned(fOnMouseLeave) then
  fOnMouseLeave(self);
end;


Danke im Vorraus

mfg
admiralkirk
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 16:52 
Zitat:
Bloß ich bekomme es nicht hin...

Und wieso nicht? Wie sieht der Code denn aus? Dein Denkansatz scheint doch schonmal logisch korrekt zu sein.
admiralkirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 17:02 
Also TImage fungiert als button ist aber ein bild... also muss bei MouseEnter ein neues Bild über das primäre,
das hatte ich gedacht könnte man über eine ImageList bewerkstelligen. Das Problem aber ist, das die TImage komponente nicht über handle verfügt und ich somit nicht das Bild aus der ImageList bekomme.
Kann mir jmd da weiter helfen?
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 19.11.08 17:03 
Zur not kann man auch 2 images übereinander nehmen und dann beim klick das obere einblenden
admiralkirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 17:04 
das ist eine gute idee, also könnte man das 2. bild auch bei Mouseenter überblenden ?!
Boldar
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1555
Erhaltene Danke: 70

Win7 Enterprise 64bit, Win XP SP2
Turbo Delphi
BeitragVerfasst: Mi 19.11.08 17:08 
Einfach das obere Bild auf visible := false stellen, bei mouseenter auf visible:=true und bei mouseleave wieder visible auf false...


Zuletzt bearbeitet von Boldar am Mi 19.11.08 17:08, insgesamt 1-mal bearbeitet
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 17:08 
Das Bild aus einer ImageList bekommst Du über GetBitmap.
admiralkirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 17:12 
also wäre das in etwa so:
Ich hab die images auf ein Panel gelegt nur zur info, nich das ihr euch wundert

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Panel1MouseEnter(Sender: TObject);
begin
  Image2.Visible := True;
end;

procedure TForm1.Panel1MouseLeave(Sender: TObject);
begin
  Image2.Visible := False;
end;


is das so richtig?
oder gibt es ne bessere möglichkeit

//EDIT
funktioniert nich, habs getestet.
is der behefel anders als Visible?
In den Element funktion is das 2. bild auf Visible = False
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 17:26 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure LoadPictureToImage(index: Integer; //Index des Image aus der Liste
                             const imgList: TImageList;
                             const Pic: TImage);
var BMP: TBitmap;
begin
  BMP := TBitmap.Create;
  try
    imgList.GetBitmap(index,BMP);
    Pic.Picture.Bitmap.Assign(BMP);
  finally
    BMP.Free;
  end;
end;
admiralkirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 17:29 
muss das bild eine Bitmap sein?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 17:32 
Delphi-Hilfe hat folgendes geschrieben:
Mit GetBitmap können Sie ein Bild in der Bilderliste als Bitmap-Objekt abrufen. Das gewünschte Bild wird im Parameter Index angegeben. GetBitmap weist das Bild dem in Image übergebenen TBitmap-Objekt zu.
whitef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 202
Erhaltene Danke: 1

Windows X
Delphi XE X
BeitragVerfasst: Mi 19.11.08 18:44 
user profile iconadmiralkirk hat folgendes geschrieben Zum zitierten Posting springen:
also wäre das in etwa so:
Ich hab die images auf ein Panel gelegt nur zur info, nich das ihr euch wundert

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Panel1MouseEnter(Sender: TObject);
begin
  Image2.Visible := True;
end;

procedure TForm1.Panel1MouseLeave(Sender: TObject);
begin
  Image2.Visible := False;
end;


is das so richtig?
oder gibt es ne bessere möglichkeit

//EDIT
funktioniert nich, habs getestet.
is der behefel anders als Visible?
In den Element funktion is das 2. bild auf Visible = False




naja hab das mal selber schnell getestet... also mouse leave find ich gar net :D
hab einfach bei der Form onMouseMove das image auf false gesetzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image1.Visible := false;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image1.Visible := true;
end;
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 18:50 
Oder mit BringToFront oder SendToBack nach vorne/hinten holen (wobei ich diesen Weg mit 2 Images nicht für optimal halte).
admiralkirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 18:57 
user profile iconwhitef hat folgendes geschrieben Zum zitierten Posting springen:
user profile iconadmiralkirk hat folgendes geschrieben Zum zitierten Posting springen:
also wäre das in etwa so:
Ich hab die images auf ein Panel gelegt nur zur info, nich das ihr euch wundert

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TForm1.Panel1MouseEnter(Sender: TObject);
begin
  Image2.Visible := True;
end;

procedure TForm1.Panel1MouseLeave(Sender: TObject);
begin
  Image2.Visible := False;
end;


is das so richtig?
oder gibt es ne bessere möglichkeit

//EDIT
funktioniert nich, habs getestet.
is der behefel anders als Visible?
In den Element funktion is das 2. bild auf Visible = False




naja hab das mal selber schnell getestet... also mouse leave find ich gar net :D
hab einfach bei der Form onMouseMove das image auf false gesetzt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image1.Visible := false;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
Image1.Visible := true;
end;


Funktioniert bei mir net mmh
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 19:07 
Und was funktioniert nicht?
whitef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 202
Erhaltene Danke: 1

Windows X
Delphi XE X
BeitragVerfasst: Mi 19.11.08 19:10 
hab mal so ne test file hochgeladen, probier das mal ob das bei dir ansatzweise funtzt!

EDIT: sry... mainform sollte jetzt dabei ;)
Einloggen, um Attachments anzusehen!


Zuletzt bearbeitet von whitef am Mi 19.11.08 19:17, insgesamt 1-mal bearbeitet
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 19:13 
Da fehlt die Mainform.
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 19.11.08 19:21 
Das Image wird doch unsichtbar, allerdings solltest Du ein zweites darunterlegen.
whitef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 202
Erhaltene Danke: 1

Windows X
Delphi XE X
BeitragVerfasst: Mi 19.11.08 19:24 
aja soll jetzt nur testweise darstellen das es so eigentlich funktioniert...

is mir schon klar das da jeweils wenn das eine verschwindet n anderes kommen soll... soll er mal tüfteln... :D
admiralkirk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Mi 19.11.08 19:42 
jo es funktioniert, aber ich muss das bild mit MousMove anwählen, weil mein bild das ganze Panel bedeckt und da das Panel net reagiert.
Das problem ist, dass es manchmal problemlos funktioniert und manchmal beim 2. bild hängen bleibt und das erste nicht wieder gezeigt wird ...
hat jmd da ne lösung?