Jump to content
Tuts 4 You

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


n00b!ICU

Recommended Posts

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

Link to comment

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

Link to comment

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

Link to comment

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.

Link to comment

@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

Link to comment

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
Link to comment

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...