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. changing font in CEdit

changing font in CEdit

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
3 Posts 2 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
    dart13
    wrote on last edited by
    #1

    Can anyone please explain me how to change font in CEdit. I tried with CWnd::SetFont() but it doesn't work.

    G 1 Reply Last reply
    0
    • D dart13

      Can anyone please explain me how to change font in CEdit. I tried with CWnd::SetFont() but it doesn't work.

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      You need to ensure that the font exists for the life of the CEdit control. Suppose you're changing the font in the OnInitDialog() handler for your class:

      BOOL MyDialog::OnInitDialog()
      {
      //...
      CFont myFont;
      myFont.CreatePointFont(120,"Arial");
      myEdit.SetFont(&myFont);
      }

      This won't work, because as soon as the OnInitDialog function exits, the myFont variable is destroyed, which destroys the font and the edit control reverts to using the standard font. You fix this by making the myFont value a member of the dialog:

      class MyDialog : public CDialog
      {
      //...
      CFont myFont;
      };
      BOOL MyDialog::OnInitDialog()
      {
      //...
      myFont.CreatePointFont(120,"Arial");
      myEdit.SetFont(&myFont);
      }

      Since the myFont variable is a member of the dialog class, it exists for as long as the dialog object, and therefore the edit control.


      Software Zen: delete this;

      D 1 Reply Last reply
      0
      • G Gary R Wheeler

        You need to ensure that the font exists for the life of the CEdit control. Suppose you're changing the font in the OnInitDialog() handler for your class:

        BOOL MyDialog::OnInitDialog()
        {
        //...
        CFont myFont;
        myFont.CreatePointFont(120,"Arial");
        myEdit.SetFont(&myFont);
        }

        This won't work, because as soon as the OnInitDialog function exits, the myFont variable is destroyed, which destroys the font and the edit control reverts to using the standard font. You fix this by making the myFont value a member of the dialog:

        class MyDialog : public CDialog
        {
        //...
        CFont myFont;
        };
        BOOL MyDialog::OnInitDialog()
        {
        //...
        myFont.CreatePointFont(120,"Arial");
        myEdit.SetFont(&myFont);
        }

        Since the myFont variable is a member of the dialog class, it exists for as long as the dialog object, and therefore the edit control.


        Software Zen: delete this;

        D Offline
        D Offline
        dart13
        wrote on last edited by
        #3

        thanx for help

        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