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 Static Text control

Resizing Static Text control

Scheduled Pinned Locked Moved C / C++ / MFC
7 Posts 4 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.
  • V Offline
    V Offline
    VCProgrammer
    wrote on last edited by
    #1

    Hi all, I just wanted to know can we increase the size of static text(label we are using in dialog box) at runtime.... like i put text in my static text at run time using SetDlgItemText(), but sometimes when text is big it is not displayed i.e text is displayed according to the size of static text control....so what i want is that my control size should increase or decrease according to the text given... Thanks in advance...

    L 1 Reply Last reply
    0
    • V VCProgrammer

      Hi all, I just wanted to know can we increase the size of static text(label we are using in dialog box) at runtime.... like i put text in my static text at run time using SetDlgItemText(), but sometimes when text is big it is not displayed i.e text is displayed according to the size of static text control....so what i want is that my control size should increase or decrease according to the text given... Thanks in advance...

      L Offline
      L Offline
      leonigah
      wrote on last edited by
      #2

      BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); CString str; CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowText(str); int iLen = str.GetLength(); int iWidth = 8*iLen;//assume 8 pixel per character GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); rect.right = iWidth; GetDlgItem(IDC_STATIC1)->MoveWindow(rect); return TRUE; }

      Nigah M Manzoor

      modified on Tuesday, July 1, 2008 7:58 AM

      V 1 Reply Last reply
      0
      • L leonigah

        BOOL CMyDlg::OnInitDialog() { CDialog::OnInitDialog(); CString str; CRect rect; GetDlgItem(IDC_STATIC1)->GetWindowText(str); int iLen = str.GetLength(); int iWidth = 8*iLen;//assume 8 pixel per character GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); rect.right = iWidth; GetDlgItem(IDC_STATIC1)->MoveWindow(rect); return TRUE; }

        Nigah M Manzoor

        modified on Tuesday, July 1, 2008 7:58 AM

        V Offline
        V Offline
        VCProgrammer
        wrote on last edited by
        #3

        Hey thanks its increasing the size but one more problem is there, where ever i put label when i run my program its showing the text at upper left corner only.....

        L 1 Reply Last reply
        0
        • V VCProgrammer

          Hey thanks its increasing the size but one more problem is there, where ever i put label when i run my program its showing the text at upper left corner only.....

          L Offline
          L Offline
          leonigah
          wrote on last edited by
          #4

          use GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); ScreenToClient(&rect); instead of GetDlgItem(IDC_STATIC1)->GetClientRect(rect);

          Nigah M Manzoor

          V 1 Reply Last reply
          0
          • L leonigah

            use GetDlgItem(IDC_STATIC1)->GetWindowRect(rect); ScreenToClient(&rect); instead of GetDlgItem(IDC_STATIC1)->GetClientRect(rect);

            Nigah M Manzoor

            V Offline
            V Offline
            VCProgrammer
            wrote on last edited by
            #5

            hey thanks it worked correctly

            S 1 Reply Last reply
            0
            • V VCProgrammer

              hey thanks it worked correctly

              S Offline
              S Offline
              savita_Bgm
              wrote on last edited by
              #6

              i also used the same code to resize my static text control it is working fine but one problem the text box width is not exactly according to the text it is little bit large. i want do like autofit to content. any idea?

              H 1 Reply Last reply
              0
              • S savita_Bgm

                i also used the same code to resize my static text control it is working fine but one problem the text box width is not exactly according to the text it is little bit large. i want do like autofit to content. any idea?

                H Offline
                H Offline
                hafizmwasim
                wrote on last edited by
                #7

                Use this method. CClientDC dc( pWnd ); CFont * pOldFont = dc.SelectObject( pWnd->GetFont()); CSize txtSize = dc.GetTextExtent(m_szText); dc.SelectObject( pOldFont);

                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