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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. About CEdit vertical center

About CEdit vertical center

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 Posters 2 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.
  • L Offline
    L Offline
    lvvvww
    wrote on last edited by
    #1

    How can I do content of CEdit vertical center? This quesiton puzzle me for a long time. Hope anyone to answer!

    H M 2 Replies Last reply
    0
    • L lvvvww

      How can I do content of CEdit vertical center? This quesiton puzzle me for a long time. Hope anyone to answer!

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      lvvvww wrote: How can I do content of CEdit vertical center? You can't. The edit control has no provision for this. You would have to roll your own custom edit control. See here to get started. Best wishes, Hans

      1 Reply Last reply
      0
      • L lvvvww

        How can I do content of CEdit vertical center? This quesiton puzzle me for a long time. Hope anyone to answer!

        M Offline
        M Offline
        Member 8103516
        wrote on last edited by
        #3

        Just in case someone is searching for a solution.

        void CCCenterText::CenterText(CString Text)
        {
        m_wndEdit.SetWindowText(Text);
        m_wndEdit.CenterWindow(&m_wndStatic); // Center the edit window vertically and horizontally

        // Calculate the height of the font
        CDC \*pDC = m\_wndEdit.GetDC();
        CFont \*pEditFont = m\_wndEdit.GetFont();
        
        CFont \*pFont = pDC->SelectObject(pEditFont);
        
        TEXTMETRIC tm;
        pDC->GetTextMetrics(&tm);
        int LineHeight = tm.tmHeight;
        
        pDC->SelectObject(pFont);
        ReleaseDC(pDC);
        
        // Get the edit control position
        CRect pos;
        m\_wndEdit.GetWindowRect(pos);
        ScreenToClient(&pos);
        
        // Adjust the height position of the edit control 
        int LineCount = m\_wndEdit.GetLineCount();
        int posHeight = LineHeight \* LineCount;
        
        m\_wndEdit.SetWindowPos(&m\_wndStatic,pos.left,pos.top,pos.Width(),posHeight,0);
        m\_wndEdit.CenterWindow(&m\_wndStatic);
        

        }

        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