主题:如何实现图片的拖动
puma1972
[专家分:0] 发布于 2005-03-23 20:30:00
愚人又有问题了:在BCB中如何实现扑克牌在窗体中的拖动,在拖动过程中如何防止图片的闪烁?
回复列表 (共1个回复)
沙发
iamdream [专家分:620] 发布于 2005-03-25 14:18:00
给你一个例子:新建一个工程,在窗体上放一个Image控件,以下是.h,.cpp文件代码:
//*.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <jpeg.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TImage *Image1;
void __fastcall Image1MouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
private: // User declarations
int m_iOldX, m_iOldY;
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
//*.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
DoubleBuffered = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
m_iOldX = X;
m_iOldY = Y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
int X, int Y)
{
if(Shift.Contains(ssLeft))
{
Image1->Left += X - m_iOldX;
Image1->Top += Y - m_iOldY;
}
}
//---------------------------------------------------------------------------
我来回复