1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| //---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
p1 = new TPiece(this,ImageList1,0,0,0,"VEGETA");
p2 = new TPiece(this,ImageList1,1,150,0,"BULMA");
p3 = new TPiece(this,ImageList1,2,300,0,"SANGOKU");
p4 = new TPiece(this,ImageList1,3,450,0,"TENSHINAN");
p5 = new TPiece(this,ImageList1,4,600,0,"BOUBOU");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
p1->Positionner(0,0);
p2->Positionner(150,0);
p3->Positionner(300,0);
p4->Positionner(450,0);
p5->Positionner(600,0);
}
//---------------------------------------------------------------------------
__fastcall TPiece::TPiece(TForm *AOwner, TImageList *liste, int index,
int posX, int posY,AnsiString n) :
TImage(AOwner)
{
listeImg = liste;
this->numero = index;
listeImg->GetBitmap(numero,Picture->Bitmap);
this->nom = n;
this->Width = Picture->Width;
this->Height = Picture->Height;
this->Parent = AOwner;
this->Top = posY;
this->Left = posX;
this->Hint = nom;
this->ShowHint = true;
this->Transparent = false;
}
//------------------------------------------------------------------------
void __fastcall TPiece::Positionner(int X, int Y)
{
this->Top = Y;
this->Left = X;
}
//------------------------------------------------------------------------
void __fastcall TPiece::MouseDown(TMouseButton button, TShiftState shift,
int X, int Y)
{
listeImg->DragCursor = crHandPoint;
listeImg->Tag=this->numero;
listeImg->SetDragImage(this->numero,X,Y);
this->deltaX = X-this->Left;
this->deltaY = Y-this->Top;
listeImg->BeginDrag(this->Parent->Handle,this->Left+X,this->Top+Y);
}
//------------------------------------------------------------------------
void __fastcall TPiece::MouseMove( TShiftState shift,
int X, int Y)
{
if(listeImg->Dragging)
listeImg->DragMove(this->Left+X,this->Top+Y);
else
this->Parent->Cursor = crHandPoint;
}
//------------------------------------------------------------------------
void __fastcall TPiece::MouseUp(TMouseButton button, TShiftState shift,
int X, int Y)
{
if(listeImg->Dragging)
{
this->Top = Y - this->deltaY;
this->Left = X - this->deltaX;
listeImg->EndDrag();
}
}
//---------------------------------------------------------------------------
le code unit1.h
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ImgList.hpp>
#include <Buttons.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TPiece;
class TForm1 : public TForm
{
__published: // Composants gérés par l'EDI
TImageList *ImageList1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // Déclarations utilisateur
public: // Déclarations utilisateur
__fastcall TForm1(TComponent* Owner);
TPiece *p1, *p2, *p3 , *p4 , *p5;
int XX,YY;
};
class TPiece : public TImage
{
TImageList *listeImg;
int numero;
AnsiString nom;
int deltaX, deltaY;
DYNAMIC void __fastcall MouseDown(TMouseButton, TShiftState, int, int);
DYNAMIC void __fastcall MouseMove( TShiftState, int, int);
DYNAMIC void __fastcall MouseUp(TMouseButton, TShiftState, int, int);
public:
__fastcall TPiece(TForm * ,TImageList *,int, int, int, AnsiString);
void __fastcall Positionner(int , int);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif |
Partager