• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1486
  • Last Modified:

ES_LEFT vs ES_RIGHT CEdit alignment

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.
0
mromeo
Asked:
mromeo
  • 4
  • 3
1 Solution
 
nonubikCommented:
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) ?
0
 
itsmeandnobodyelseCommented:
With VC6 i couldn't reproduce the problem.

Both definitions

    EDITTEXT        IDC_EDIT1,256,81,12,14,ES_LEFT | ES_AUTOHSCROLL

    EDITTEXT        IDC_EDIT1,256,81,12,14,ES_RIGHT | ES_AUTOHSCROLL

show only one character. When increasing width by one

    EDITTEXT        IDC_EDIT1,256,81,13,14,ES_LEFT | ES_AUTOHSCROLL

    EDITTEXT        IDC_EDIT1,256,81,13,14,ES_RIGHT | ES_AUTOHSCROLL

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

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

Regards, Alex




0
 
mromeoAuthor Commented:
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");
myEditText->SetFont(myFont);


0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
itsmeandnobodyelseCommented:
>> 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?

What about ES_AUTOHSCROLL?

Regards, Alex
0
 
mromeoAuthor Commented:
I tried with and without ES_AUTOHSCROLL.  It didn't change anything.  I'm trying to put the word 'OR' in the field.
0
 
itsmeandnobodyelseCommented:
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


0
 
mromeoAuthor Commented:
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
0
 
itsmeandnobodyelseCommented:
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");
    GetDlgItem(IDC_EDIT1)->SetFont(myFont);
    CRect e1, e2, e3;
    GetDlgItem(IDC_EDIT1)->GetWindowRect(&e1);  
    DWORD dws = GetDlgItem(IDC_EDIT1)->GetStyle();  
    DWORD dwsex = GetDlgItem(IDC_EDIT1)->GetExStyle();  
    GetWindowRect(&e2);
    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);
    pEdit->SetFont(myFont);
    pEdit->ShowWindow(SW_NORMAL);      
    pEdit->SetWindowText("OR");


Regards, Alex
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now