- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Keeping a glyph's transparent area transparent.

Question:

Under some video modes, the transparent area of the standard TBitBtn glyphs turns gold or maroon. How can I keep the standard TBitBtn's glyph transparent?

Answer:

The following example demonstrates a technique where the
transparent portion of the glyph is filled with the background color
of the button, making the glyph appear transparent.

Example:

function InitStdBitBtn(BitBtn : TBitBtn;
                       kind : TBitBtnKind) : bool;
var
  Bm1 : TBitmap;
  Bm2 : TBitmap;
begin
  Result := false;
  if Kind = bkCustom then exit;
  Bm1 := TBitmap.Create;
  case Kind of
    bkOK : Bm1.Handle := LoadBitmap(hInstance, 'BBOK');
    bkCancel : Bm1.Handle := LoadBitmap(hInstance, 'BBCANCEL');
    bkHelp : Bm1.Handle := LoadBitmap(hInstance, 'BBHELP');
    bkYes : Bm1.Handle := LoadBitmap(hInstance, 'BBYES');
    bkNo : Bm1.Handle := LoadBitmap(hInstance, 'BBNO');
    bkClose : Bm1.Handle := LoadBitmap(hInstance, 'BBCLOSE');
    bkAbort : Bm1.Handle := LoadBitmap(hInstance, 'BBABORT');
    bkRetry : Bm1.Handle := LoadBitmap(hInstance, 'BBRETRY');
    bkIgnore : Bm1.Handle := LoadBitmap(hInstance, 'BBIGNORE');
    bkAll : Bm1.Handle := LoadBitmap(hInstance, 'BBALL');
  end;
  Bm2 := TBitmap.Create;
  Bm2.Width := Bm1.Width;
  Bm2.Height := Bm1.Height;
  bm2.Canvas.Brush.Color := ClBtnFace;
  bm2.Canvas.BrushCopy(Rect(0, 0, bm2.Width, bm2.Height),
                       Bm1,
                       Rect(0, 0, Bm1.width, Bm1.Height),
                       bm1.canvas.pixels[0,0]);
  bm1.Free;
  LockWindowUpdate(BitBtn.Parent.Handle);
  BitBtn.Kind := kind;
  BitBtn.Glyph.Assign(bm2);
  LockWindowUpdate(0);
  bm2.Free;
  Result := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  InitStdBitBtn(BitBtn1, bkOk);
end;



* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile