View previous topic :: View next topic |
Author |
Message |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
|
Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Thu Apr 02, 2009 12:46 pm Post subject: |
|
|
I'm not quite sure I understand your question, but if you're asking what I think you are, I'd suggest to create a loop which inserts "\r\n" every n characters, like this for instance: Code: | int lineLength = 10;
string buffer = TextBox.Text;
for(int=lineLength-1;i<buffer.Length;i+=lineLength)
buffer= buffer.Insert(i,"\r\n"); |
Tell me if this helped.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
|
Back to top |
|
 |
TraxMate Master Cheater
Reputation: 0
Joined: 01 Mar 2008 Posts: 363
|
Posted: Thu Apr 02, 2009 1:14 pm Post subject: |
|
|
You could check for how many times the user presses the space space key on the keyboard, and on X number of spaces you change row.
|
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Thu Apr 02, 2009 1:49 pm Post subject: |
|
|
doesn't TextBox.Text.Length return the number of characters in the textbox? If you put it on a keyup event handler then you could move to the next row when you reach the length you want.
|
|
Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu Apr 02, 2009 2:29 pm Post subject: |
|
|
How do I know where the end is..
_________________
Intel over amd yes. |
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Thu Apr 02, 2009 3:54 pm Post subject: |
|
|
Example of how to get the length of the text in pixels:
Code: | Dim ruler As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(New Bitmap(1, 1)), _
pixLen As Integer
pixLen = CType(ruler.MeasureString(TextBox1.Text, TextBox1.Font).Width, Integer) |
Compare that to the width of the control
|
|
Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Thu Apr 02, 2009 4:40 pm Post subject: |
|
|
With this code the text should be divided only at the end of a word:
Code: | int lineLength = 100;
string buffer = TextBox.Text;
string lineEndChar = " ";// Replace with punctuation mark to only divide at a new sentence.
for(int=lineLength-1;i<buffer.Length;i+=lineLength)
{
int offset = 0;
bool doContinue=false;
while(!doContinue){
if(buffer.SubString(i-offset,1)==lineEndChar && buffer.SubString(i-offset-1,1) != "\n")
doContinue = true; }
else if (buffer.SubString(i+Offset) == lineEndChar &&(buffer.SubString(i+Offset+1 != "\n"))
offset = -1*offset, doContinue = true;
else
offset++;
}
buffer= buffer.Insert(i+offset,"\n");
} | If this does not meet your criterias, please be a little more specific about what you want.
Edit: This will work best with strings that do not contain newlines and do not have too long character sequences.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
Back to top |
|
 |
Spawnfestis GO Moderator
Reputation: 0
Joined: 02 Nov 2007 Posts: 1746 Location: Pakistan
|
Posted: Thu Apr 02, 2009 4:50 pm Post subject: |
|
|
What do you mean when you should generate a new line?
Just add a "\r\n" for each period you have in your text, or what are you trying to do here?
If you're just breaking rows in a textbox, you could do the above as well...
_________________
CLICK TO HAX MAPLESTORAY ^ !!!! |
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Thu Apr 02, 2009 5:10 pm Post subject: |
|
|
Spawnfestis wrote: | What do you mean when you should generate a new line? | I thought that simply meant when the length of the text equals the width of the control you're typing in, basically a wordwrap kind of thing but with actual line breaks. The character count methods would only work if you're using a mono-spaced font, hence my post (Which was in VB, not C like the others) but it is .NET so the functions are basically the same.
Naablet wrote: | For instance it would break the text in the middle of a sentence | After finding where the length of the text in pixels = the width of the control, get the length of the text in characters and check each character backwards from there until you reach a space or a hyphen, then insert the line break there.
|
|
Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Fri Apr 03, 2009 3:10 am Post subject: |
|
|
shhac wrote: | Spawnfestis wrote: | What do you mean when you should generate a new line? | I thought that simply meant when the length of the text equals the width of the control you're typing in, basically a wordwrap kind of thing but with actual line breaks. The character count methods would only work if you're using a mono-spaced font, hence my post (Which was in VB, not C like the others) but it is .NET so the functions are basically the same.
Naablet wrote: | For instance it would break the text in the middle of a sentence | After finding where the length of the text in pixels = the width of the control, get the length of the text in characters and check each character backwards from there until you reach a space or a hyphen, then insert the line break there. |
I have the width of the textbox. And the width of the total text. Can I find the point where the width of the text is the same as the width of the control?
Is it possible that I could step thru every char and meassure it?
_________________
Intel over amd yes. |
|
Back to top |
|
 |
shhac Expert Cheater
Reputation: 0
Joined: 30 Oct 2007 Posts: 108
|
Posted: Fri Apr 03, 2009 6:53 am Post subject: |
|
|
Naablet wrote: | Can I find the point where the width of the text is the same as the width of the control? | Yes, use something like Code: | If pixLen < textbox.width Then
... |
Naablet wrote: | Is it possible that I could step thru every char and meassure it? | Yes, but depending on the length of the text and the number of breaks you expect and when you're running this code, you'd find there may be better ways to do it.
E.g. if you run it each time a key is pressed then you only need to check if the current length is > the control's width, but if you're running it after they've finished and click a button or something and it is a loooong string, then you may find its faster to do some sort of bisection algorithm... of course one character at a time would still work.
Something else you'd need to consider would be if they use backspace/delete key. You might need to get the current position of the caret and then remove all instances of line breaks you've inserted after that, and then reapply the line breaks to it.
Also after looking through the code you've been provided with, if you're not using C, but VB, it is better to use the vbCrLf constant for a new line.
|
|
Back to top |
|
 |
|