Posted November 21, 200717 yr Hoy there fellas, I have this little problem here..... Im stuck with a text-line problem, so here it goes:I want to code an app which automatically selects a new line for each lets say 12 chars has been written, and then continue so on....Anyone with any suggestions that might could help me out?/Dearest, n00b
November 21, 200717 yr Well without knowing exactly what your doing it's hard to say. Are you wanting like an array split or just a loop and process 12 at a time?
November 21, 200717 yr Author I want a some sorta loop that processes 12 chars at each time....That beeing said, I mean ofc that i want the code to work while im typing into the textbox..../n00b
November 21, 200717 yr cant you yust "count" length of entered text, and when its dividable with 12 (or whatever you need) just add new line character to it?!
November 21, 200717 yr Author As Ted said, like a line break wich is automatic @ChupaChu: Well, that has been my solution so far - but as we all know, that would not work properly as it will by "accident" divide some of the written text @EVERYONE: A good solution for this errornous problem would be much appreciated, thx /Regards, n00b
November 22, 200717 yr Did you try and use the TextChanged property? In that, for the current line of that textbox/richtextbox you can count the entered characters, and if that is 12 then textbox1.Text += Environment.Newline;Think this should help.Oricode.
November 22, 200717 yr Author @oricode:Thought of that, and tested ofc MANY times - but as you can imagine, it didnt exactly work: for (int i = 0; i < textBox2.Lines.Length; i++) { if (textBox2.Lines.Length == 12) { textBox2.Text += Environment.NewLine; } } It will only ****-up, and stop working.... So im still stuck im afraid ://n00b
November 22, 200717 yr why it stops working?does it mean that iw works ok until "some" event accours?
November 22, 200717 yr Author Well, its stops working because it cannot read from "current" line only.... That is my biggest issue, and therefor Im seeking help for it /n00b
November 23, 200717 yr Ok that code won't work. Because it will enter an infinite loop on each text change and hang! Try this instead, somewhat "not-so perfect", but working 100% for your problem. Declare globally , int j=0;for (int i = 0; i < textBox1.Lines.Length; i++) { if (j == i) { if (textBox1.Lines[i].Length == 12) { SendKeys.Send("{ENTER}"); j = i+1; } } }If you want to improvise it you can have a look here : http://www.codeproject.com/vb/net/textbox_line_limit.aspOricode. Edited November 23, 200717 yr by oricode
November 23, 200717 yr Author @Oricode: Thx alot mate, helps me very much Now I need to figure the more advanced parts out myself somehow /n00b
Create an account or sign in to comment