Board index » delphi » length of Non-proportional text in TEdit

length of Non-proportional text in TEdit

Is there a way to tell whether a particular string
in a NONproportional font will fit in a Edit box?
There is no "ActualLengthInPixels" property for TEdits.
Thanks,
Charly Olson

 

Re:length of Non-proportional text in TEdit


-- Is there a way to tell whether a particular string
in a NONproportional font will fit in a Edit box?
There is no "ActualLengthInPixels" property for TEdits.
Thanks,
Charly Olson
*** Charles B. Olson ***
seuss...@compuserve.com

Re:length of Non-proportional text in TEdit


On 9 Jan 1998 11:47:58 GMT, "Charles B. Olson"

Quote
<seuss...@compuserve.com> wrote:
> Is there a way to tell whether a particular string
> in a NONproportional font will fit in a Edit box?

Use the TCanvas TextWidth function. Since the TEdit Canvas property is
proected, you normally cannot access it. So do something like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  W : Integer;
  Canvas : TControlCanvas;
begin
  Canvas := TControlCanvas.Create;
  Canvas.Control := Edit1;
  W := Canvas.TextWidth(Edit1.Text);
  ShowMessage(IntToStr(W));
end;

--
Rick Rogers (TeamB) | Fenestra Technologies

Re:length of Non-proportional text in TEdit


On 9 Jan 1998 12:38:18 GMT, "Charles B. Olson"

Quote
<seuss...@compuserve.com> wrote:
> Is there a way to tell whether a particular string

Your first post came through and was already answered <g>.

--
Rick Rogers (TeamB) | Fenestra Technologies

Re:length of Non-proportional text in TEdit


On Fri, 09 Jan 1998 13:15:33 GMT, r...@fenestra.com (Rick Rogers

Quote
(TeamB)) wrote:
> So do something like this

Sorry, the code I posted leaks memory. Here's the corrected version:

procedure TForm1.Button1Click(Sender: TObject);
var
  W : Integer;
  Canvas : TControlCanvas;
begin
  Canvas := TControlCanvas.Create;
  try
    Canvas.Control := Edit1;
    W := Canvas.TextWidth(Edit1.Text);
    ShowMessage(IntToStr(W));
  finally
     Canvas.Free;
  end;
end;

--
Rick Rogers (TeamB) | Fenestra Technologies

Other Threads