开发者

C# winforms: move text from one textbox to another

开发者 https://www.devze.com 2023-02-06 10:57 出处:网络
I have a winform appl开发者_StackOverflow社区ication with two textboxes. The textboxes are multilined and has 5 rows.

I have a winform appl开发者_StackOverflow社区ication with two textboxes. The textboxes are multilined and has 5 rows.

When the user enters more than 5 lines of text in the first textbox I want the text to continue in the second textbox. And if he/she deletes text from the first textbox I want the text to move back from the second to the first one...

I have tried to solve this in my code by checking how many rows the first textbox has and moved text between the two textboxes. But it doesnt work that well so I wonder if anyone got a better solution??


You could accomplish this by registering for the TextChanged events on the TextBox controls. Then in the event handler, manually inspect the Text property and set focus to the appropriate control. However, what you are describing sounds like it may lead to an inconsistent user experience.

From a UX standpoint I would suggest changing the approach. First of all do you really need to split the text in the UI, or could it be split afterward in the business layer? If you do need it split in the UI, you could have a single TextBox which allows the user to enter the full text, and below it have 2 read-only textbox's which display the 2 split segments as they type (you would also use the TextChanged event logic to do this as they type).

I hope this helps.


Have you tried checking the visible Characters in the text box? or text box character length?

0

精彩评论

暂无评论...
验证码 换一张
取 消