Hola amigos, quería meter un TImage dentro de un ScrollBox y entonces pongo la TImage en Autosize y cuando la imagen es mayor que el ScrollBox pues salen las barras de desplazamiento y hasta ahi bien. Pues ahora lo que quiero es que pueda hacer clic en la imagen y sin soltar arrastre la imagen y se desplacen las barras del scrollbox y no tengo ni idea de como hacerlo pero encontre este codigo en Delphi: h**p://delphi.about.com/od/vclusing/l/aa050603a.htm
Creo que por lo que entiendo en el texto hace lo que quiero pero no se como pasarlo a C++Builder y he intentado con esto pero no compila siquiera:
UNIT1.H
Código:
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Graphics.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TScrollBox *ScrollBox1;
TImage *Image1;
void __fastcall Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
void __fastcall MyDragDrop(TObject *Sender, TObject *Source, int X, int Y);
void __fastcall MyDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool &Accept);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
TPoint *TheSpot;
//---------------------------------------------------------------------------
#endif
UNIT1.CPP
Código:
//-----------------------------------------------------------------------------
#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 MyDragDrop(TObject *Sender, TObject *Source, int X, int Y)
{
//dropping an Image?
if(Source == TImage)
{
//on itself?
if(Sender == TImage)
{
TImage(Source)->Left = TImage(Source)->Left + X - TheSpot->x;
TImage(Source)->Top = TImage(Source)->Top + Y - TheSpot->y;
}
else
{
//or, somewhere inside ScrollBox!
TImage(Source)->Left = X - TheSpot->x;
TImage(Source)->Top = Y - TheSpot->y;
}
}
}
//-----------------------------------------------------------------------------
void __fastcall MyDragOver(TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool Accept)
{
if(Source == TImage)
Accept = true;
Accept = (Source is TImage);
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TheSpot->x = X;
TheSpot->y = Y;
Image1->BeginDrag(true);
}
//-----------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Image1->OnDragOver = MyDragOver;
Image1->OnDragDrop = MyDragDrop;
}
//-----------------------------------------------------------------------------
¿Podeis ayudarme a pasarlo al builder?