![]() |
Re: SpeedButton - kein Bild?
Auch hierfür gibt es eine Lösung:
Das Bitmap verwendet das untere linke Pixel als transparente Farbe. Bei einer Verknüpfung ist dieses Pixel schwarz, somit wird der schwarze Verknüpfungs-Pfeil transparent. Durch die Zeile
Delphi-Quellcode:
sollte das Problem allerdings behoben sein.
SpeedButton1.Glyph.TransparentColor := clNone;
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var ICO: TIcon; IconIndex: Word; buf: array[0..max_path] of Char; begin ICO := TIcon.Create; try StrPCopy(buf, Edit1.Text); IconIndex := 0; ICO.Handle := ExtractAssociatedIcon(hInstance, buf, IconIndex); SpeedButton1.Glyph.Width := ICO.Width; SpeedButton1.Glyph.Height := ICO.Height; SpeedButton1.Glyph.TransparentColor := clNone; SpeedButton1.Glyph.Canvas.Brush.Color := Color; SpeedButton1.Glyph.Canvas.FillRect(Rect(0, 0, SpeedButton1.Glyph.Width, SpeedButton1.Glyph.Height)); SpeedButton1.Glyph.Canvas.Draw(0, 0, ICO); finally ICO.Free; end; end; |
Re: SpeedButton - kein Bild?
... ja, so funktioniert's - Danke.
Der SpeedButton muss aber mindestens 36*36 Pixel haben um das Icon unterzubringen. Ich werde dennoch auch noch versuchen das gleiche mit SHGetFileInfo abbilden zu können, dann könnte man alternativ auch die kleineren Icons verwenden. Vielleicht hat's auch schon jemand umgesetzt. |
Re: SpeedButton - kein Bild?
Zitat:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var ICO: TIcon; SHFileInfo: TSHFileInfo; begin ICO := TIcon.Create; try FillChar(SHFileInfo, SizeOf(SHFileInfo), #0); SHGetFileInfo(PChar(Edit1.Text), 0, SHFileInfo, SizeOf(SHFileInfo), SHGFI_Icon or SHGFI_SmallIcon); //SHGFI_LargeIcon für die großen Symbole ICO.Handle := SHFileInfo.hIcon; SpeedButton1.Glyph.Width := ICO.Width; SpeedButton1.Glyph.Height := ICO.Height; SpeedButton1.Glyph.TransparentColor := clNone; SpeedButton1.Glyph.Canvas.Brush.Color := Color; SpeedButton1.Glyph.Canvas.FillRect(Rect(0, 0, SpeedButton1.Glyph.Width, SpeedButton1.Glyph.Height)); SpeedButton1.Glyph.Canvas.Draw(0, 0, ICO); finally ICO.Free; end; end; |
Re: SpeedButton - kein Bild?
... super, funzt auch.
Werde noch ein bisschen testen ob noch irgendwelche Macken auftauchen. Danke - Gruss MarLe |
Re: SpeedButton - kein Bild?
Wenn der SpeedButton kleiner ist als 36*36 Pixel
dann wird mit SHGFI_SmallIcon der SpeedButton total verhunzt?!? |
Re: SpeedButton - kein Bild?
Jaja, das leigt denke ich mal an der Umwandlung Icon -> Bitmap.
Kann es in Deinem Fall denn nicht eine ToolBar mit ToolButtons sein? Hier kannst Du mit einer ImageList arbeiten und das Icons kann direkt als Icons eingefügt werden. Da dürfte so ein Problem nicht auftauchen. Zu dem eigentlichen Problem: Habe mir gerade mit einem Trick beholfen - nicht die sauberste Lösung, aber es funktioniert: - Du weist dem SpeedButton schon zur Designzeit (also bevor Du kompilierst) im OI ein Bitmap zu, das die Abmessungen 16x16 Pixel hat. - In dem Quellcode streichst Du einfach diese beiden Zeilen:
Delphi-Quellcode:
Dann funktioniert's !
SpeedButton1.Glyph.Width := ICO.Width;
SpeedButton1.Glyph.Height := ICO.Height; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:47 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz