I'm trying to find the width of a tedit.text field. I do not have a canvas.
I've been investigating the GETTEXTEXTENTPOINT function, but then I get
stuck on know what the HDC is for a CLASS (TFORM).
I just have a form that has a bunch of TEDITs on it. The values in the
TEDIT.TEXT can change and I want to expand the width of the box if need be.
But to do that I need to be able to check what the width is.
Is there a way I'm missing that will make this easier?
Thanks in advance.
You can use any canvas. Your form has one. If the form's font is the same as
the tedit, then it's no problem...
LB Cid <swe>
{GetTextExtentPoint is provided for compatibility with 16-bit versions of
Windows.
Win32-based applications should call the GetTextExtentPoint32 function,
which provides more accurate results. }
procedure TForm1.Button2Click(Sender: TObject);
var
DC: HDC;
TextSize: TSize;
SaveFont: HFont;
begin
DC := GetDC(0);
SaveFont := SelectObject(DC, Edit1.Font.Handle);
GetTextExtentPoint32(DC, PChar(Edit1.Text),
Length(Edit1.Text), TextSize);
SelectObject(DC, SaveFont);
ShowMessage(Format('Height= %d Width = %d', [TextSize.cy, TextSize.cx]));
ReleaseDC(0, DC);
end;
Then set Edit1.Width to TextSize.cx plus the border.
--
Jon Perry
pe...@globalnet.co.uk
Jim Schoen <Inp...@qsi-r2.com> wrote in message
news:7uni1u$5f...@forums.borland.com...
> Using D4.
>
> I'm trying to find the width of a tedit.text field. I do not have a
canvas.
> I've been investigating the GETTEXTEXTENTPOINT function, but then I get
> stuck on know what the HDC is for a CLASS (TFORM).
>
> I just have a form that has a bunch of TEDITs on it. The values in the
> TEDIT.TEXT can change and I want to expand the width of the box if need
be.
> But to do that I need to be able to check what the width is.
>
Because it doesn't work for proportional fonts.
Mike Orriss (TeamB)
(Unless stated otherwise, my replies relate to Delphi 4.03/5.00)
(Unsolicited e-mail replies will most likely be ignored)
Bill, thanks for giving me the parameters for finding the HDC for
GETTEXTEXTENTPOINT32. I guess that I won't need to go through that if I can
tap into the Canvas and simply do a TFormVariable.CANVAS.TEXTWIDTH ('test
this line');
Jim
Ralph Friedman (TeamB) <ralphf...@email.com> wrote in message
news:VA.000005a...@della.garlin...
> In message <7uni1u$5f...@forums.borland.com>, Jim Schoen stated:
> > I'm trying to find the width of a tedit.text field. I do not have a
canvas.
> > I've been investigating the GETTEXTEXTENTPOINT function, but then I get
> > stuck on know what the HDC is for a CLASS (TFORM).
> >