Solved

ES_LEFT vs ES_RIGHT CEdit alignment

Posted on 2004-09-14
10
1,313 Views
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.
0
Comment
Question by:mromeo
  • 4
  • 3
10 Comments
 
LVL 16

Expert Comment

by:nonubik
Comment Utility
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
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
 

Author Comment

by:mromeo
Comment Utility
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
>> 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:mromeo
Comment Utility
I tried with and without ES_AUTOHSCROLL.  It didn't change anything.  I'm trying to put the word 'OR' in the field.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
Comment Utility
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
 

Author Comment

by:mromeo
Comment Utility
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
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 150 total points
Comment Utility
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and 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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now