Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Icon aus ImageList ins StringGrid laden! (https://www.delphipraxis.net/178178-icon-aus-imagelist-ins-stringgrid-laden.html)

Alterauge 21. Dez 2013 09:05

Icon aus ImageList ins StringGrid laden!
 
Hallo,

habe da noch eine Frage :-) !

1.) habe ein StringGrid
2.) habe eine ImageList

So, wenn im StringGrid sagen wir mal:

Delphi-Quellcode:
if StringGrid1.Cells [1, StringGrid1.FixedRows] ='Eingang' then begin // steht
Dann möchte ich gerne in die 6 Spalte ein Icon zeichen!


Delphi-Quellcode:
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  if StringGrid1.Cells [1, StringGrid1.FixedRows] ='Eingang' then begin


  end;
end;
Was muss ich machen?
Finde leider nur Beispiele für ein DBGrid!

Uwe Raabe 21. Dez 2013 09:59

AW: Icon aus ImageList ins StringGrid laden!
 
Delphi-Quellcode:
var
  X, Y: Integer;
begin
  if (ACol = 6) and (ARow >= StringGrid1.FixedRows) and (StringGrid1.Cells [1, ARow] ='Eingang') then begin
    { eventuell noch zentrieren }
    X := Rect.Left;
    Y := Rect.Top;
    ImageList1.Draw(StringGrid1.Canvas, X, Y, 0, true); { 0 = erstes Image in ImageList }
  end;
end;

Alterauge 21. Dez 2013 15:32

AW: Icon aus ImageList ins StringGrid laden!
 
Hallo Uwe Raabe,
danke läuft ! :-)

Wie mache ich das mit dem zentrieren?

Danke :-)

Uwe Raabe 21. Dez 2013 20:13

AW: Icon aus ImageList ins StringGrid laden!
 
Zitat:

Zitat von Alterauge (Beitrag 1240686)
Wie mache ich das mit dem zentrieren?

Delphi-Quellcode:
var
  P: TPoint;


    P := CenterPoint(Rect);
    X := P.X - ImageList1.Width div 2;
    Y := P.Y - ImageList1.Height div 2;

Alterauge 4. Aug 2014 16:37

AW: Icon aus ImageList ins StringGrid laden!
 
Liste der Anhänge anzeigen (Anzahl: 1)
hallo Uwe,

habe noch ein Problem, mit dem zentrieren :-(

Helmi 4. Aug 2014 17:04

AW: Icon aus ImageList ins StringGrid laden!
 
wohl eher so:
(Klammern)

Delphi-Quellcode:
     X := (P.X - ImageList1.Width) div 2;
     Y := (P.Y - ImageList1.Height) div 2;

Uwe Raabe 4. Aug 2014 17:47

AW: Icon aus ImageList ins StringGrid laden!
 
Zitat:

Zitat von Helmi (Beitrag 1267473)
wohl eher so:
(Klammern)

Delphi-Quellcode:
     X := (P.X - ImageList1.Width) div 2;
     Y := (P.Y - ImageList1.Height) div 2;


Wohl eher nicht! Die linke Koordinate des Image bekommt man, wenn man vom Mittelpunkt die halbe Breite abzieht.

Beispiel: Rect(10, 10, 210, 210), ImageWidth = 100, ImageHeight = 100

P = CenterPoint(Rect) = (110, 110)
X = P.x - ImageWidth/2 = 110 - 50 = 60

Linke Kante des Bilds ist dann bei 60, was 50 von der linken Kante des Rechtecks (10) entfernt ist.
Rechte Kante des Bilds ist dann auf 60 + 100 = 160, was genau 50 von der rechten Kante (210) entfernt ist.

Mit deiner Formel käme man auf:

X = (P.x - ImageWidth)/2 = (105 - 100)/2 = 2.5

Damit liegt die linke Kante des Bilds schon mal außerhalb des Rechtecks...


was irgendwie nicht richtig aussieht.

Helmi 4. Aug 2014 17:52

AW: Icon aus ImageList ins StringGrid laden!
 
stimmt, sorry - du hast recht - das war zu schnell getippt


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:50 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz