Q:

How do I enlarge a TImage in Delphi when my cursor is over it?

I am using a VCL Application in Delphi. I have a TImage. I want to enlarge the TImage slightly when my cursor is over it. Does anybody know how to do this?

A:

There are many ways.
Personally, I'd create a new custom control specifically for the purpose, so it can be reused.
But if you need a quick version, you can simply use the control's OnMouseEnter and OnMouseLeave events:
procedure TForm1.Image1MouseEnter(Sender: TObject);
var
  R: TRect;
begin
  R := Image1.BoundsRect;
  R.Inflate(6, 6, 6, 6);
  Image1.BoundsRect := R;
end;

procedure TForm1.Image1MouseLeave(Sender: TObject);
var
  R: TRect;
begin
  R := Image1.BoundsRect;
  R.Inflate(-6, -6, -6, -6);
  Image1.BoundsRect := R;
end;

This is actually more robust than you might think. For instance, if you place the cursor above the image, so that it is enlarged, and then press Ctrl+Alt+Del and move the cursor away, you will find that the image is restored to its original size when you get back to the desktop.

