Frage

I use D2007 and TcxButton with a glyph image from Devexpress but it should be the same for any image. The button have 2 states and on the second state I want to draw an overlay over the original image. So in this case I have 1 Imagelist called Main. The main image is stored on index 0 and the overlay on index 1. I made a small testproject but don't get this to work:

procedure TForm6.CheckBox1Click(Sender: TObject);
var
  vBm: TBitMap;
  vOverlay: TOverLay;
begin
  if Main.GetBitmap(0, vBm) then
  begin
    vOverlay := 1;
    if CheckBox1.Checked then
    begin
      // procedure DrawOverlay(Canvas: TCanvas; X, Y: Integer;  ImageIndex: Integer; Overlay: TOverlay; Enabled: Boolean = True); overload;
      Main.DrawOverlay(vBm.Canvas, 0, 0, vOverlay, True);
    end
    else
    begin
      Main.DrawOverlay(vBm.Canvas, 0, 0, vOverlay, False);
    end;
  end;
end;

So I assume main image and overlay must be in the same Imagelist ? Now it even don't compiles, I got

[DCC Error] Unit6.pas(41): E2250 There is no overloaded version of 'DrawOverlay' that can be called with these arguments

Edit:

Tried the suggested solution. It compiled but nothing happened. Here is a link to the project https://www.dropbox.com/sh/tk5n7frkbveyxbz/D1O4Ags9fS/Overlay

War es hilfreich?

Lösung

You will have to create a bitmap before using it with GetBitmap.
You will have to use Overlay to assign an overlay index to one of the images in the list.

var
  vBm: TBitMap;
  vOverlay: TOverLay;
begin
  vBm:= TBitMap.Create; // create Bitmap before using GetBitmap
  try
  if Main.GetBitmap(0, vBm) then // can be done but will be painted over by DrawOverlay
  begin
    vOverlay := 1; // use eg. 1 of the possible 4 indices (0..3)
    Main.Overlay(1,vOverlay); // define second image in List to overlay index 1 to enable it as overlay image
    if CheckBox1.Checked then
    begin
      Main.DrawOverlay(vBm.Canvas, 0, 0, 0 , vOverlay, True);
    end
    else
    begin
      Main.DrawOverlay(vBm.Canvas, 0, 0,0, vOverlay, False);
    end;

    //TheButton.Glyph.Assign(vBm);
  end;
  finally
    vBm.Free;
  end;
end;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top