Jump to content
Tuts 4 You

Some Small Problems That I Need Some Help With...


n00b!ICU

Recommended Posts

Posted

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

Posted

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?

Posted

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

Posted

Like a line break?

Ted.

Posted

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?!

Posted

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

Posted

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.

Posted

@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

Posted

why it stops working?

does it mean that iw works ok until "some" event accours?

Posted

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

Posted (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.asp

Oricode.

Edited by oricode
Posted

@Oricode:

Thx alot mate, helps me very much :D

Now I need to figure the more advanced parts out myself somehow :P

/n00b

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...