Hola, para esto podemos usar el evento WM_WINDOWPOSCHANGING:- Incluye en el .h de tu formulario lo siguiente:
private: // User declarations
void __fastcall WMWindowPosChanging(TMessage &Msg);
public: // User declarations
...
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_WINDOWPOSCHANGING, TMessage, WMWindowPosChanging);
END_MESSAGE_MAP(TForm);
- Y en el .cpp lo siguiente:
//-----
void __fastcall TForm1::WMWindowPosChanging(TMessage &Msg)
{
LPWINDOWPOS WinPos = reinterpret_cast<LPWINDOWPOS>(Msg.LParam);
if (WinPos->x < 0)
WinPos->x = 0;
else if ((WinPos->x + WinPos->cx) > Screen->Width)
WinPos->x = Screen->Width - WinPos->cx;
if (WinPos->y < 0)
WinPos->y = 0;
else if ((WinPos->y + WinPos->cy) > Screen->Height)
WinPos->y = Screen->Height - WinPos->cy;
}
//-----
Espero que te sirva.
Saludos.