[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


ES_LEFT vs ES_RIGHT CEdit alignment

Posted on 2004-09-14
Medium Priority
Last Modified: 2013-12-03
I have an MFC application which creates edit fields.  In certain cases the text is aligned left and in others it is aligned right.  The problem is that when I use ES_RIGHT for right alignment, the text does not fit always fit in the edit field.  For example, if I have an edit field that is only 2 characters wide and it has 2 chars in it, the text displays fine if it is aligned left.  The same edit box aligned left will cut off the text so that only the first character shows.  I am using a monospaced font, so I know that it is not a font/character issue.  Making the edit box bigger is not an option for me.  Is there some padding or border or some property of the font and/or cedit that needs to be changed or set?  Thanks.
Question by:mromeo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
LVL 16

Expert Comment

ID: 12063629
I'm not sure I follow: you have an edit field that is only 2 characters wide and it has 2 chars in it. Does it matter if it's right or left aligned (as long as there can be no more chars) ?
LVL 39

Expert Comment

ID: 12064967
With VC6 i couldn't reproduce the problem.

Both definitions



show only one character. When increasing width by one



both show two characters, either with or without having the focus.

So, either it looks like a font or caret problem.

Regards, Alex


Author Comment

ID: 12065082
Did you try it with a monospaced font?  Try doing:

myFont->CreateFont(14, 7, 0, 0, FW_NORMAL, 0, 0, 0, 0, 1, 2, 1, 34, "Lucida Console");

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 39

Expert Comment

ID: 12066326
>> Did you try it with a monospaced font

Yes, but same result as when using a true type font.

What's the string you are using? Maybe it depends on the letters?

Did you set initial focus to that edit field?


Regards, Alex

Author Comment

ID: 12066380
I tried with and without ES_AUTOHSCROLL.  It didn't change anything.  I'm trying to put the word 'OR' in the field.
LVL 39

Expert Comment

ID: 12066800
It works with 'OR' in both cases (or not if i make a width of 12).

Could you post the dialog definition of resource file (open rc file as text file after closing all resource windows)?

Maybe there is another field overlapping? What's your caret (text cursor)? A small vertical 1 pixel bar?

Do you need an edit field? Or is it readonly? Then, try a static text field.

Regards, Alex


Author Comment

ID: 12066830
It's not a dialog box.  I create edit fields on the fly and place editable text in them.  If I'm putting 2 chars in the edit field, I make the edit box 16 pixels wide and use use a 7 pixel wide font.  The font creation is shown above
LVL 39

Accepted Solution

itsmeandnobodyelse earned 600 total points
ID: 12067422
Please post code of edit field creation.

>> I make the edit box 16 pixels

That looks strange as i took the same font as you  but have a width of 20 (13 dialog units) when showing both letters. Maybe the ratio of your rectangle isn't ok as edit fields are sized on base of dialog units rather than on pixels.

Look at that code where i place a dynamic edit field below my edit field of  the resource file:

    CFont* myFont = new CFont;
    myFont->CreateFont(14, 7, 0, 0, FW_NORMAL, 0, 0, 0, 0, 1, 2, 1, 34, "Lucida Console");
    CRect e1, e2, e3;
    DWORD dws = GetDlgItem(IDC_EDIT1)->GetStyle();  
    DWORD dwsex = GetDlgItem(IDC_EDIT1)->GetExStyle();  
    e3 = e1 + e2.TopLeft();
    e3.top += 30;
    e3.bottom += 30;
    e3.right = e3.left + 16;       // Width is 16 pixels now (instead of 20)
    CEdit* pEdit = new CEdit;
    pEdit->Create(dws | dwsex, e3, this, IDC_EDIT1 + 1);

Regards, Alex

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question