Limit the max number of chars per line in a textbox

前端 未结 5 1910
慢半拍i
慢半拍i 2021-01-25 23:24

Say I have the following:



        
5条回答
  •  攒了一身酷
    2021-01-25 23:42

    Given that you're responding to keydown events I assume that you want to make sure that the string behind the TextBox adheres to the "60 chars per line" rule. If that's the case you should make an event that subscribes to the TextChanged event on the TextBox. There you can fix up the text and either truncate or break apart lines that are too long.

    (edit) To solve the display portion you can do as Kafuka suggested: just make the box wide enough to hold 60 characters, and use a monospaced font if you want to be sure. If you've made sure the string is correct this should fall into line easily.

提交回复
热议问题