I failed in replicating the problem on my
old computer!!
Here is the code I used:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
Panel1: TPanel;
procedure Image1Click(Sender: TObject);
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
);
procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
sx, sy: Integer;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
panel: TPanel absolute Sender;
begin
if Sender is TPanel then
begin
panel.Tag := 1;
sx := x;
sy := y;
end;
end;
procedure TForm1.Image1Click(Sender: TObject);
begin
end;
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
dx, dy: Integer;
panel: TPanel absolute Sender;
begin
if Sender is TPanel then
begin
if panel.Tag = 1 then
begin
dx := x-sx;
dy := y-sy;
panel.Left := panel.Left + dx;
panel.Top := panel.Top + dy;
end;
end;
end;
procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
panel: TPanel absolute Sender;
begin
if Sender is TPanel then
panel.Tag := 0;
end;
end.
I think the image you are using is too big, maybe?
I assumed you are using Windows?
What bit depths do you have in your desktop settings?
Can you provide a small example that we can test?
I most likely would do the background painting myself, not using TImage. In addition to that I would bypass the WM_ERASEBKGND message, it is not needed since the image covers everything.
Edit:
Hold a second, the image you provided has a bad area that is bigger than the panel you are moving. Is that another panel? if so, then it is that panel that is not getting painted, not the form.