C# – Limit the max number of chars per line in a textbox

cnetwpf

Say I have the following:

<TextBox TextWrapping="Wrap" 
         AcceptsReturn="True" 
         AcceptsTab="True" 
         MaxLines="3000"/>

Is there a way I can limit the max number of chars per line to 60?

I have seen ways to do it via keydown events, but that does not seem to be foolproof (ie what about pasting in a long block of text).

Best Answer

Choose a mono spaced font. And calculate the width of your textbox that has 60 chars.

Related Topic