ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Limit the size of a text layer
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

AndNit

Brazil
83 Posts

Posted - Jun 07 2024 :  12:48:09  Show Profile  Reply
[Redacted]

xequte

39053 Posts

Posted - Jun 07 2024 :  16:13:19  Show Profile  Reply
Hi

There is no built in functionality for that. You would need to reset the Key parameter of the TImageEnView.OnTextEditorKeyDown event:

https://www.imageen.com/help/TImageEnView.OnTextEditorKeyDown.html

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

39053 Posts

Posted - Jun 07 2024 :  21:03:40  Show Profile  Reply
Hi

Here is a better method:

// Prevent user from entering too much text
procedure Tfmain.ImageEnView1LayerNotifyEx(Sender: TObject; layer: Integer; event: TIELayerEvent);
const
  Maximum_Text_Length = 10;
var
  editor: TIEEdit;
  pos: Integer;
  s: string;
begin
  if ( Maximum_Text_Length > 0 ) and  ( event =  ielTextEditorChange ) then
  begin
    if ImageEnView1.LayersTextEditor is TIEEdit then
    begin
      editor := TIEEdit( ImageEnView1.LayersTextEditor );
      if Length( editor.Text ) > Maximum_Text_Length then
      begin
        pos := editor.SelStart;
        s := editor.Text;
        SetLength( s, Maximum_Text_Length );
        editor.Text := s;
        editor.SelStart := pos;
      end;
    end;
  end;
end;


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

39053 Posts

Posted - Jun 10 2024 :  00:23:45  Show Profile  Reply
Hi

Yes, there is not really an easy way to do that, unfortunately.

If the text layer has AutoSize enabled, then you could check the TextEditor width and height and if its too big, delete the last character. Alternatively calculating the width and height of the text yourself (i.e. using Canvas.TextWidth/TextHeight).





Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

39053 Posts

Posted - Sep 02 2024 :  17:36:32  Show Profile  Reply
Please see:

https://docwiki.embarcadero.com/Libraries/Athens/en/Vcl.Graphics.TCanvas.TextExtent

Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: