Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


{.Net} How do I break rows?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Apr 02, 2009 11:09 am    Post subject: {.Net} How do I break rows? Reply with quote

I'm trying to create a inputbox for .net but I'm not sure on how to handle the text. I don't know the lenght of the text becuase it's a user input control. So the text can vary really.
How would I know when to generate a new line? I don't want them to look randomly Sad

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Thu Apr 02, 2009 12:46 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Apr 02, 2009 12:52 pm    Post subject: Reply with quote

Odecey wrote:
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.

hmm. That would be random Sad For instance it would break the text in the middle of a sentence Sad

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
TraxMate
Master Cheater
Reputation: 0

Joined: 01 Mar 2008
Posts: 363

PostPosted: Thu Apr 02, 2009 1:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Thu Apr 02, 2009 1:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Thu Apr 02, 2009 2:29 pm    Post subject: Reply with quote

How do I know where the end is..
_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Thu Apr 02, 2009 3:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
Odecey
Master Cheater
Reputation: 1

Joined: 19 Apr 2007
Posts: 259
Location: Scandinavia

PostPosted: Thu Apr 02, 2009 4:40 pm    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Thu Apr 02, 2009 4:50 pm    Post subject: Reply with quote

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? Smile
If you're just breaking rows in a textbox, you could do the above as well...

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Thu Apr 02, 2009 5:10 pm    Post subject: Reply with quote

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
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Fri Apr 03, 2009 3:10 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Fri Apr 03, 2009 6:53 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites