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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
//.dfm
object Form87: TForm87
Left = 0
Top = 0
Caption = 'Form87'
ClientHeight = 299
ClientWidth = 635
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object StatusBar1: TStatusBar
Left = 0
Top = 280
Width = 635
Height = 19
Panels = <
item
Text = 'Carte Gauche:'
Width = 80
end
item
Width = 50
end
item
Text = 'CarteHaut'
Width = 80
end
item
Width = 50
end
item
Text = 'Carte'
Width = 80
end
item
Width = 50
end>
ExplicitLeft = 288
ExplicitTop = 288
ExplicitWidth = 0
end
object Button1: TButton
Left = 264
Top = 249
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end
//le .h
//---------------------------------------------------------------------------
#ifndef Unit87H
#define Unit87H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TForm87 : public TForm
{
__published: // Composants gérés par l'EDI
TStatusBar *StatusBar1;
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // Déclarations utilisateur
void __fastcall SendToStatusPanel(int x, int y,int Elem);
void __fastcall EMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall EMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
int X, int Y);
void __fastcall EMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
bool MouseBtnPressed;
int CarteNr;
int PWight;
public: // Déclarations utilisateur
__fastcall TForm87(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm87 *Form87;
//---------------------------------------------------------------------------
#endif
//le code
// ---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit87.h"
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm87 *Form87;
// ---------------------------------------------------------------------------
__fastcall TForm87::TForm87(TComponent* Owner) : TForm(Owner),
MouseBtnPressed(false), CarteNr(0), PWight(0) {
}
// ---------------------------------------------------------------------------
void __fastcall TForm87::EMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y) {
TPanel* LePanel = dynamic_cast<TPanel*>(Sender);
MouseBtnPressed = false;
SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
}
// ---------------------------------------------------------------------------
void __fastcall TForm87::EMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y) {
TPanel* LePanel = dynamic_cast<TPanel*>(Sender);
MouseBtnPressed = true;
SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
}
// ---------------------------------------------------------------------------
void __fastcall TForm87::EMouseMove(TObject *Sender, TShiftState Shift, int X,
int Y)
{
TPanel* LePanel = dynamic_cast<TPanel*>(Sender);
if (LePanel && MouseBtnPressed) {
LePanel->Left += X;
LePanel->Top += Y;
SendToStatusPanel(LePanel->Left, LePanel->Top, LePanel->Tag);
}
}
// ---------------------------------------------------------------------------
void __fastcall TForm87::SendToStatusPanel(int x, int y, int Elem) {
StatusBar1->Panels->operator[](1)->Text = x;
StatusBar1->Panels->operator[](3)->Text = y;
StatusBar1->Panels->operator[](5)->Text = Elem;
}
// ---------------------------------------------------------------------------
void __fastcall TForm87::Button1Click(TObject *Sender) {
TPanel* UnPanel = new TPanel(this);
const Larg = 50;
const Space = 5;
UnPanel->Parent = this;
UnPanel->Width = Larg;
++CarteNr;
UnPanel->Top = 0;
UnPanel->Left = PWight;
PWight += Larg + Space;
UnPanel->Tag = CarteNr;
UnPanel->Caption = "Carte " + IntToStr(CarteNr);
UnPanel->OnMouseMove = EMouseMove;
UnPanel->OnMouseUp = EMouseUp;
UnPanel->OnMouseDown = EMouseDown;
UnPanel->Visible = true;
SendToStatusPanel(UnPanel->Left, UnPanel->Top, UnPanel->Tag);
}
// --------------------------------------------------------------------------- |
Partager