Hola.
Contestando al título, para centrar un TImage en un TScrollBox podes hacer:
Código PHP:
...
Image->Left = ( ScrollBox->Width - 2 - Image->Width ) / 2;
Image->Top = ( ScrollBox->Height - 2 - Image->Height ) / 2;
Y si entendí bién la consulta del mensaje, lo haría al modo de este ejemplo:
Código PHP:
// (valores a tu gusto)
TPoint pos = (Point)( 1, 1);
int inc = 10;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Image2->Left = pos.x;
Image2->Top = pos.y;
}
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
TRect sbr = ScrollBox1->ClientRect; // rect. cliente
// tratamiento de teclas
switch ( Key ) {
case VK_LEFT : pos.x -= inc; break;
case VK_RIGHT : pos.x += inc; break;
case VK_UP : pos.y -= inc; break;
case VK_DOWN : pos.y += inc; break;
}
// desplazamiento horizontal
if ( pos.x < 0 ) {
ScrollBox1->ScrollBy( inc, 0 );
pos.x = 0;
}
if ( pos.x + Image2->Width > sbr.right ) {
ScrollBox1->ScrollBy( -inc, 0 );
pos.x = sbr.right - GetSystemMetrics( SM_CXHSCROLL ) + 2;
}
// desplazamiento vertical
if ( pos.y < 0) {
ScrollBox1->ScrollBy( 0, inc );
pos.y = 0;
}
if ( pos.y + Image2->Height > sbr.bottom ) {
ScrollBox1->ScrollBy( 0, -inc );
pos.y = sbr.Bottom - GetSystemMetrics( SM_CXVSCROLL ) + 2;
}
Image2->Left = pos.x;
Image2->Top = pos.y;
}
Resultado:
Saludos