//---------------------------------------------------------------------------
__fastcallTForm1::TForm1(TComponent*
Owner)
: TForm(Owner)
{
FDragging = false;
TempPanel = new TPanel(this);
TempPanel->Parent = this;
TempPanel->BorderStyle = bsNone;
TempPanel->BevelInner = bvNone;
TempPanel->BevelOuter = bvNone;
TempPanel->FullRepaint = false; //remove
for BCB1 (false by default)
//subclass the WindowProc to supress the
WM_ERASEBKGND message
OldPanelWP = TempPanel->WindowProc;
TempPanel->WindowProc = NewPanelWP;
}
void
__fastcall TForm1::NewPanelWP(TMessage &Msg)
{
if (Msg.Msg != WM_ERASEBKGND) Msg.Result = false;
else OldPanelWP(Msg);
}
void
__fastcall TForm1::Image1MouseDown(TObject *Sender, TMouseButton
Button,
TShiftState Shift, int X, int Y)
{
FDragging = true;
OldX = X;
OldY = Y;
TempPanel->Left = Image1->Left;
TempPanel->Top = Image1->Top;
TempPanel->Height = Image1->Height;
TempPanel->Width = Image1->Width;
TempPanel->Visible = true;
SetCapture(TempPanel->Handle);
Image1->Parent = TempPanel;
Image1->Left = 0;
Image1->Top = 0;
}
void
__fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState
Shift,
int
X, int Y)
{
if (FDragging == true)
{
TempPanel->Left = TempPanel->Left + (X - OldX);
TempPanel->Top = TempPanel->Top + (Y - OldY);
}
}
void
__fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton
Button,
TShiftState Shift, int X, int Y)
{
TempPanel->Visible = false;
Image1->Left = TempPanel->Left;
Image1->Top = TempPanel->Top;
Image1->Parent = this;
FDragging = false;
}
void
__fastcall TForm1::FormClose(TObject *Sender, TCloseAction
&Action)
{
TempPanel->WindowProc = OldPanelWP;
delete TempPanel;
}
|