BCB6 图片在某一区域里拖动代码

 

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "pngimage"
#pragma link "pngextra"
#pragma resource "*.dfm"
TForm1 *Form1;
bool MouseDownBZ;		//鼠标按下标志(自行加入) 
int MouseX;			//鼠标坐标(自行加入)
int MouseY;			//鼠标坐标(自行加入) 
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1 (TComponent * Owner):
TForm (Owner)
{
}

//---------------------------------------------------------------------------
void
  __fastcall
TForm1::Image1MouseDown (TObject * Sender,
			 TMouseButton Button, TShiftState Shift, int X, int Y)
{
  MouseDownBZ = true;
  MouseX = X;
  MouseY = Y;
}

//---------------------------------------------------------------------------
void __fastcall
TForm1::Image1MouseMove (TObject * Sender, TShiftState Shift, int X, int Y)
{
  int MinXMove = 0;
  int MinYMove = 0;
  int MaxXMove = Panel1->Width - Image1->Width;
  int MaxYMove = Panel1->Height - Image1->Height;
  int LSXMove = Image1->Left + (X - MouseX);
  int LSYMove = Image1->Top + (Y - MouseY);
  if (MouseDownBZ == true)
    {
      if ((LSXMove >= MinXMove) && (LSXMove <= MaxXMove)
	  && (LSYMove >= MinYMove) && (LSYMove <= MaxYMove))
	{
	  Image1->Left = LSXMove;
	  Image1->Top = LSYMove;
	}
    }
}

//---------------------------------------------------------------------------
void __fastcall
TForm1::Image1MouseUp (TObject * Sender, TMouseButton Button,
		       TShiftState Shift, int X, int Y)
{
  MouseDownBZ = false;
  MouseX = X;
  MouseY = Y;
}

//---------------------------------------------------------------------------
void __fastcall
TForm1::FormCreate (TObject * Sender)
{
  Image1->Parent->DoubleBuffered = true;
}

//---------------------------------------------------------------------------

 

http://down.qiannao.com/space/file/meetrice/-6211-7684-8f6f-4ef6/dragimginarea.rar/.page

 

 

posted @ 2010-07-05 17:22  meetrice  阅读(559)  评论(0编辑  收藏  举报