Board index » delphi » TImageList.Draw Not Refreshing!!

TImageList.Draw Not Refreshing!!

Hi
I'm trying to make my own gradient speedbutton, so I took over the
Speedbutton.Paint procedure.  Then I use a TImageList.Draw to draw the
image on the speedbutton's canvas.  However, the bitmap is not visible
until something causes it to refresh.  I tried invalidating itself,
but it goes into an infinite loop.  Here's the code:

procedure TdkSpeedButton.MDrawTransBitmap(MyCanvas: TCanvas; MyBitmap:
TBitmap; MOffset: Integer; MEnabled: Boolean; MAlign: Integer);
var
   FImageList : TImageList;
   PictureIndex:integer;
   FImageLoc: TPoint;
begin
   //MyCanvas.Draw(0,0, MyBitmap);

   try
      FImageList := TImageList.CreateSize(MyBitmap.Width,
MyBitmap.Height);
      PictureIndex := FImageList.AddMasked(MyBitmap, clWhite);

      FImageLoc.Y:=(Self.Height-Self.Glyph.Height) Div 2;
      case MAlign of
      0: begin //centered
            FImageLoc.X:=(Self.Width-MyBitmap.Width) Div 2;
         end;
      1: begin
            FImageLoc.X:=FMargin;
         end;
      2: begin
            FImageLoc.X:=Self.Width-FMargin-MyBitmap.Width;
         end;
      end;
      FImageList.Draw(MyCanvas, FImageLoc.X+MOffset,
FImageLoc.Y+MOffset, PictureIndex,dsNormal,itImage,False);

   finally
      FImageList.Free;
   end;

end;

procedure TdkSpeedButton.Paint;
var
   MyOffset: integer;
   MyShadowOffset: integer;

begin
   inherited;
   DrawButtonFace(Self.Canvas, Self.ClientRect, 2, bsNew, True,
Self.FState=bsDown, False);
   //draw Text;
   Self.Canvas.Font.Assign(Self.FFont);

   //determine Offset
   case FAlignment of
   0: begin //centered
         FXOffset:=(Width-Self.Canvas.TextWidth(FCaption)) div 2;
      end;
   1: begin //Left
         FXOffset:=FMargin;
      end;
   2: begin //Right
         FXOffset:=Self.Width-FMargin-Self.Canvas.TextWidth(FCaption);
      end;
   end;
   FYOffset:=(Height-Self.Canvas.TextHeight(FCaption)) div 2;

   if Self.FState = bsDown then
   begin
      MyOffset:=4;
      MyShadowOffset:=5;
      //draw Gradient
      MGradientRect(Self.Canvas, Rect(1,0,Self.Width-1,Self.Height-1),
Self.FGradientColor, Self.FColor );
   end else
   begin
      MyOffset:=0;
      MyShadowOffset:=3;
      //draw reverse Gradient
      MGradientRect(Self.Canvas, Rect(1,0,Self.Width-1,Self.Height-1),
Self.FColor, Self.FGradientColor);
   end;

   //draw background gradient

   //draw text shadow

   Self.Canvas.Brush.Style:=bsClear;
   Self.Canvas.Font.Color:=Self.FColor;
   Self.Canvas.TextRect(Rect(2, 2, Self.Width-3, Self.Height-3),
FXOffset+MyShadowOffset, FYOffset+MyShadowOffset, FCaption);

   if Self.Enabled then
   begin
      //enabled
      Self.Canvas.Font.Color:=clBlack;

   end else begin
      //not enabled.
      Self.Canvas.Font.Color:=clGray;

   end;

   Self.Canvas.TextRect(Rect(2, 2, Self.Width-3, Self.Height-3),
FXOffset+MyOffset, FYOffset+MyOffset, FCaption);

   //bitmap
   if not Self.Glyph.Empty then begin
      MDrawTransBitmap(Self.Canvas, Self.Glyph, MyOffset, True,
FAlignment);

   end;

end;

After a few screen refreshes, the image appears, but not until!  Any
suggestions?  What trigger do I need for the canvas to refresh?
Pleaseeee!

 

Re:TImageList.Draw Not Refreshing!!


Quote
"Douglas Keene, M.D." wrote:

> Hi
> I'm trying to make my own gradient speedbutton, so I took over the
> Speedbutton.Paint procedure.  Then I use a TImageList.Draw to draw the
> image on the speedbutton's canvas.  However, the bitmap is not visible
> until something causes it to refresh.  I tried invalidating itself,
> but it goes into an infinite loop.  Here's the code:

[snip]

A guess...... try the Update method

from on-line help......

"Use Update to provide immediate feedback to the user that cannot wait
for the Windows paint message to arrive.

Update does not invalidate the control, but simply forces a repaint of
any regions that have already been invalidated. "

Dave

Other Threads