Einzelnen Beitrag anzeigen

Benutzerbild von FriFra
FriFra

Registriert seit: 19. Apr 2003
1.291 Beiträge
 
Delphi 2005 Professional
 
#1

Button-Glyph aus 2 ImageLists

  Alt 16. Jul 2005, 16:51
Wenn man 2 ImageLists verwendet wovon eine die aktiven und die andere die inaktiven Images beinhaltet, kann man diese auch verwenden um Glyphs für BitBtn bzw. Speedbuttons zu erzeugen.

Delphi-Quellcode:
  function GlyphFromImageLists(Source1, Source2: TImageList; Index: integer;
    BkColor: TColor): TBitmap; overload;
  var
    bmp1, bmp2: TBitmap;
    R1, R2: TRect;
    bColor1, bColor2: TColor;
  begin
    bColor1 := Source1.BkColor;
    bColor2 := Source2.BkColor;
    Source1.BkColor := BkColor;
    Source2.BkColor := BkColor;
    bmp1 := TBitmap.Create;
    bmp2 := TBitmap.Create;
    Result := TBitmap.Create;
    try
      Source1.GetBitmap(Index, bmp1);
      Source2.GetBitmap(Index, bmp2);
      R1.Left := 0;
      R1.Top := 0;
      R1.Right := bmp1.Width;
      R1.Bottom := bmp1.Height;
      R2.Left := bmp1.Width;
      R2.Top := 0;
      R2.Right := bmp1.Width * 2;
      R2.Bottom := bmp1.Height;
      Result.Width := bmp1.Width * 2;
      Result.Height := bmp1.Height;
      Result.Canvas.CopyRect(R1, bmp1.Canvas, R1);
      Result.Canvas.CopyRect(R2, bmp2.Canvas, R1);
    finally
      bmp1.Free;
      bmp2.Free;
      Source1.BkColor := bColor1;
      Source2.BkColor := bColor2;
    end;
  end;
  function GlyphFromImageLists(Source1, Source2: TImageList; Index: integer):
      TBitmap; overload;
  begin
    Result := GlyphFromImageLists(Source1, Source2, Index, clBtnFace);
  end;
Anwendung:
Delphi-Quellcode:
BitBtn1.Glyph.Assign(GlyphFromImageLists(ImageList1, ImageList2, 21));
BitBtn1.NumGlyphs := 2;
Elektronische Bauelemente funktionieren mit Rauch. Kommt der Rauch raus, geht das Bauteil nicht mehr.
  Mit Zitat antworten Zitat