Autor Beitrag
fuulf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 24



BeitragVerfasst: Mo 04.01.10 15:31 
Hallo,
warum funktioniert folgender Code nicht?


ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    BitBtn1: TBitBtn;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var  bm1, bm2: tbitmap;
begin
  bm1 := tbitmap.Create;
  bm2 := tbitmap.create;

  bm1.LoadFromFile('Bilddatei.bmp');

  bm2.Canvas.StretchDraw(Rect(0,0, 9, 9), bm1);

  bitbtn1.Glyph := bm2;

  bm1.free;
  bm2.free;
end;

end.


Also der BitBtn1 bleibt unverändert und hat nicht Bilddatei.bmp

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 04.01.10 15:46 
Die BitBtns ärgern mich auch regelmäßig. Hier würde ich erstmal folgendes probieren. Anstelle der normalen Zuweisung würde ich mit Assign arbeiten:
ausblenden Delphi-Quelltext
1:
2:
//bitbtn1.Glyph := bm2; nicht so
BitBtn1.Glyph.Assign(bm2); // sondern so

Außerdem solltest du vor dem Malen auf bm2 die Größe setzen, also
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  bm2 := tbitmap.create;
  bm1.LoadFromFile('Bilddatei.bmp');

  bm2.Width := 42;
  bm2.Height := 42;
  bm2.Canvas.StretchDraw(Rect(0,0, 9, 9), bm1);


Und dann bei Bedarf ein paar bitbtn1.Refresh; // oder Repaint oder Update einstreuen, das hilft auch manchmal.

_________________
We are, we were and will not be.