FAQ一覧へ インデックスへ

アイコンをビットマップに変換


質問

BitBtnやSpeedButtonにアイコンを表示させたいのですが
アイコンをビットマップに変換する方法はありますか。



答え

アイコンファイルを読み込んできて,CanvasにDrawしてやればいいです。



var
  Ico: TIcon;
begin
  Ico:= TIcon.Create;
  try
    Ico.LoadFromFile('A:\DELPHI\IMAGES\ICONS\FACTORY.ICO');
    BitBtn1.Glyph.Height := Ico.Height;
    BitBtn1.Glyph.Width := Ico.Width;
    BitBtn1.Glyph.Canvas.Draw(0,0,Ico);

    SpeedButton1.Glyph.Height := Ico.Height;
    SpeedButton1.Glyph.Width := Ico.Width;
    SpeedButton1.Glyph.Canvas.Draw(0,0,Ico);
  finally
    Ico.Free;
  end;
end;