Resizing Controls and Texts
-
Hello all, I have a SDI application that uses a CFormView class to create a window and this window has 2 buttons and 2 edit boxes. I can resize this window, like minimize and maximize, but the controls all stay at the same place. I know that it's possible to move the controls based on window size. But what i want to do is, as the window is expanded the controls and it's text content to grow proportionally and same when the window is shrinked. Is that possible to do? i.e., increase/decrease size of controls and texts per window size. Any sample code will help. Thanks in advance.
-
Hello all, I have a SDI application that uses a CFormView class to create a window and this window has 2 buttons and 2 edit boxes. I can resize this window, like minimize and maximize, but the controls all stay at the same place. I know that it's possible to move the controls based on window size. But what i want to do is, as the window is expanded the controls and it's text content to grow proportionally and same when the window is shrinked. Is that possible to do? i.e., increase/decrease size of controls and texts per window size. Any sample code will help. Thanks in advance.
OnSize() method which respond to the change of windows could do this job
// Resize the list control contained in the view to
// fill the entire view when the view's window is
// resized. CMyView is a CView derived class.
void CMyView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// Resize list to fill the whole view.
m_List.MoveWindow (0, 0, cx, cy);
}1. keep the original size of dialog, suppose Old_width is original width of dialog. We also deal with the height like this 2. use GetWindowRect( LPRECT lpRect ), which Copies the dimensions of the bounding rectangle of the CWnd object to the structure pointed to by lpRect. From it you get New_Width (it is new width of dialog now) 3. calculate rate = Old_width/ New_Width . 4. use
CWnd* GetDlgItem(
int nID
) const;to get pointer(suppose ptr) of button or other control, use ptr->GetWindowRect( BtnRect ) to get boundary rect of button ( or other ..) calculate new rect of button( suppose new_btn_rect ) through rate and BtnRect (the height also shoud be consided) 5. use ptr->MoveWindows(new_btn_rect ) to move button and change its size
-
Hello all, I have a SDI application that uses a CFormView class to create a window and this window has 2 buttons and 2 edit boxes. I can resize this window, like minimize and maximize, but the controls all stay at the same place. I know that it's possible to move the controls based on window size. But what i want to do is, as the window is expanded the controls and it's text content to grow proportionally and same when the window is shrinked. Is that possible to do? i.e., increase/decrease size of controls and texts per window size. Any sample code will help. Thanks in advance.
There are several ways to do the re-positioning of controls. If you just want to experiment a bit for yourself, you can start by following the first answer and familiarize yourself with the functionality. If you want to see how others have done it, here are a couple of CodeProject articles: MFC/C++ Helper Class for Window Resizing[^] Control Positioning and Sizing using a C++ Helper Class[^] Simple and more powerful resizable dialog[^] EasySize - Dialog resizing in no time![^] ResizableLib[^] There are several other articles, just follow the "Related Articles" links in the right hand side bar on the article pages. My final suggestion is to be prepared to drop the idea of resizing the text. I was involved with a project many years ago where we had to do exactly what you have described and we ended up throwing it away because we were unable to make it look good in all cases. Especially handling text on buttons kept causing problems. As I said, it was a long time ago, so maybe you can find a solution that works well for you. Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty