在VC ++ 6.0(MFC)中,控件如:Button,EditBox和Static Text如何从表单底部移动到表单顶部。
答案 0 :(得分:4)
您可以使用CWnd :: MoveWindow()来移动控件。 CWnd :: GetDlgItem()将检索给定控件ID的CWnd。
从窗口的类中调用一些伪代码,这些窗口是控件的父级:
RECT windowRect;
GetClientRect( &windowRect );// Bounds of the current window
CWnd* controlWindow = GetDlgItem( controlId );
RECT controlRect;
controlWindow->GetWindowRect( &controlRect );//control rectangle
ScreenToClient( &controlRect );//control rectangle in the coordinate system of the parent
const int vertOffset = windowRect.top - controlRect.top;//how much to adjust
controlRect.top += vertOffset;
controlRect.bottom += vertOffset;
controlWindow->MoveWindow( &controlRect );