bitmap is not transparent on menuitem and form? lazarus / 39-Graphics ---------------------------------------------------------------------- vkhoa · 2014-08-03 11:46 I have a code like this to assign icon to menuitem first place a menu with a menuitem named "menuitem1" Code: [Select]Unit Unit1; {$mode objfpc}{$H+} Interface Uses         Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus; Type { TForm1 }         TForm1 = Class(TForm) MainMenu1: TMainMenu; MenuItem1: TMenuItem;                 micon:tbitmap; Procedure FormCreate(Sender: TObject); Procedure FormPaint(Sender: TObject);         Private                 { private declarations }         Public                 { public declarations }         End; Var         Form1: TForm1; Implementation {$R *.lfm} { TForm1 } Procedure TForm1.FormCreate(Sender: TObject); Begin    micon:=tbitmap.Create;    micon.Width:=22;micon.Height:=16;    micon.TransparentColor:=clblack;    micon.canvas.Brush.Color:=clyellow;    micon.Canvas.Ellipse(1,1,21,16);    menuitem1.Bitmap:=micon; end; Procedure TForm1.FormPaint(Sender: TObject); Begin    canvas.Draw(50,50,micon); end; End. I want the icon to be transparent at the black color but this code didn't work. Many thanks to anyone can show me how to do it! ---------------------------------------------------------------------- howardpc · 2014-08-03 13:18 Remove the form OnPaint handler (you want the image painted on the menubar, not on the form), and add an ImageList to the form. Then change the form's OnCreate method to something like the following: Code: [Select]unit mainMenuIcons; {$mode objfpc}{$H+} interface uses   Forms, Controls, Graphics, menus; type   { TForm1 }   TForm1 = class(TForm)     ImageList1: TImageList;     MainMenu1: TMainMenu;     MenuItem1: TMenuItem;     procedure FormCreate(Sender: TObject);   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject); var   bmp: TBitmap; begin   mainmenu1.Images:=ImageList1;   MenuItem1.ImageIndex:=0;   bmp:=TBitmap.Create;   try     bmp.SetSize(24, 24);     bmp.TransparentColor:=clBlack;     bmp.Transparent:=True;     bmp.Canvas.Brush.Color:=clYellow;     bmp.Canvas.Ellipse(2, 2, 14, 14);     ImageList1.Add(bmp, nil);   finally     bmp.Free;   end; end; end. Of course you can also set the mainmenu's Images property and the menuitem's ImageIndex property in the Object Inspector, rather than in code if you prefer. ---------------------------------------------------------------------- vkhoa · 2014-08-03 13:39 from your hint, I did it simply add the code Code: [Select]micon.transparent:=true;thanks very much