15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


fonts in edit controls

Philip Beck -- splinta@cix.compulink.co.uk
Tuesday, February 27, 1996

Hi,
I'm trying to create a simple class derived from CEdit which will allow 
me to control what characters are input, and to set the colour and font 
used.

The problem I'm having is with locating the character's height within the 
single line edit control. 

The two commands :
                        xxx.CreateFont(......);
                        SetFont(&xxx);
should be enough but when I put the focus in the edit control the cursor 
(and any text) appear as follows :

         single line edit control 
         _______________________________   _         _
        |                               |   | X       |
 _  int |                               |  _|         |
|_leading    ______       |             |             |
        |   |      |      |             |             |   cell 
        |  |        |     |             |             |  height
        |  |        |     |             |             |
        |  |        |     |             |             |
        |  |        |     |             |             |
        |__|________|_____|_____________|            _|
            |______|      |
            
             zero         flashing cursor
             
The space marked 'X' is what I need to remove, otherwise I can only ever 
place a tiny font in the edit control.

Any help would be very much appreciated.

Phil.




Fredrik Gunne -- fge@agema.se
Thursday, February 29, 1996

[Mini-digest: 4 responses]

> I'm trying to create a simple class derived from CEdit which will allow 
> me to control what characters are input, and to set the colour and font 
> used.
> 
> The problem I'm having is with locating the character's height within the 
> single line edit control. 
> 
> The two commands :
>                         xxx.CreateFont(......);
>                         SetFont(&xxx);
> should be enough but when I put the focus in the edit control the cursor 
> (and any text) appear as follows :
> 
>          single line edit control 
>          _______________________________   _         _
>         |                               |   | X       |
>  _  int |                               |  _|         |
> |_leading    ______       |             |             |
>         |   |      |      |             |             |   cell 
>         |  |        |     |             |             |  height
>         |  |        |     |             |             |
>         |  |        |     |             |             |
>         |  |        |     |             |             |
>         |__|________|_____|_____________|            _|
>             |______|      |
>             
>              zero         flashing cursor
>              
> The space marked 'X' is what I need to remove, otherwise I can only ever 
> place a tiny font in the edit control.
> 
> Any help would be very much appreciated.
> 
> Phil.

I've also had problems resizing edit-control's fonts. In my
application, the user can zoom in and out during the time the CEdit is
active. To zoom, I use ScaleViewport, which works for all my drawn
objects (i.e. rectangles, circles etc). However, to "zoom" the CEdit, I
need to change the size of the CEdit (MoveWindow) and change the font
size (SetFont).

However, sometimes I experienced problems similar to yours. The CEdit would look 
like this:

>         |                               |   | X       |
>  _  int |                               |  _|         |
> |_leading    ______                     |             |
>         |   |      |                    |             |   cell 
>         |  |        |                   |             |  height
>         |  |        |                   |             |
>         |                               |             |
>         |                               |             |
>         |_______________________________|            _|
>                      
>             
>              zero         NO flashing cursor

That is, the text was clipped, and the cursor simply wasn't there.

After several hours, I found out the following:
When the CEdit's font is changed, and the text won't fit in the CEdit,
the CEdit's formatting rectangle (see CEdit::)SetRect is not resized to
allow for the new font height automatically.  If you then use
MoveWindow to change the CEdit's size, the formatting rectangle will
remain the same.

Therefore, I do this each time I change the font or resize the CEdit:
* Use DrawText with the DT_CALCRECT-flag to calculate the smallest size
  necessary to fit the text.
* If this size is greater than current, do CEdit::SetRect() with new size

So my advice is to play around with SetRect.

Regards
Fredrik

-----From: "Brad Wilson, Crucial Software" 

>> The space marked 'X' is what I need to remove, otherwise I can only ever 
>> place a tiny font in the edit control.

You can't remove X; what you should do, instead, is resize the edit control
to be taller.

--
Brad Wilson, Crucial Software     crucial@ix.netcom.com    +1 (810) 620-9803
Custom software engineering services for Microsoft Windows NT and Windows 95

"A suited man smiled, said: 'It's just a matter of time; you can have the
 world at your feet by tomorrow, just sign on this line.'"   - Dream Theater
-----From: Barry Tannenbaum 

Check out GetTextMetrics.  The returned TEXTMETRIC structure should have the
information that you need to resize your edit control to fit the font.

        - Barry

--------------------------------------------------------------------------------

3DV Technology, Inc              Phone: (603) 595-2200, X228
410 Amherst St., Suite 150       Fax:   (603) 595-2228
Nashua, NH  03063                Net:   barry@dddv.com

-----From: mikeblas@interserv.com

It is hard to guess what you're doing because you don't explain how you 
determine the height you pass to CreateFont().

Are you using the height of the edit control?  Are you converting from dialog 
units to pixels?  Are you in the right mapping mode?  Are you selecting the 
right precisions so that you don't let Windows round to the nearest, more 
efficiently managable size?

.B ekiM
--
TCHAR szDisc[] = _T("These words are my own; I do not speak for Microsoft.");





| Вернуться в корень Архива |