n00b!ICU Posted November 21, 2007 Posted November 21, 2007 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
Pimp.exe Posted November 21, 2007 Posted November 21, 2007 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?
n00b!ICU Posted November 21, 2007 Author Posted November 21, 2007 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
ChupaChu Posted November 21, 2007 Posted November 21, 2007 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?!
n00b!ICU Posted November 21, 2007 Author Posted November 21, 2007 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
oricode Posted November 22, 2007 Posted November 22, 2007 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.
n00b!ICU Posted November 22, 2007 Author Posted November 22, 2007 @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
ChupaChu Posted November 22, 2007 Posted November 22, 2007 why it stops working?does it mean that iw works ok until "some" event accours?
n00b!ICU Posted November 22, 2007 Author Posted November 22, 2007 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
oricode Posted November 23, 2007 Posted November 23, 2007 (edited) 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, 2007 by oricode
n00b!ICU Posted November 23, 2007 Author Posted November 23, 2007 @Oricode: Thx alot mate, helps me very much Now I need to figure the more advanced parts out myself somehow /n00b
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now