Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Resizing Controls and Texts

Resizing Controls and Texts

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Don Guy
    wrote on last edited by
    #1

    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.

    D S 2 Replies Last reply
    0
    • D Don Guy

      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.

      D Offline
      D Offline
      digitalspace xjtu
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D Don Guy

        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.

        S Offline
        S Offline
        SoMad
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups