TextArea Question

How can I detect when a line of text reaches the right-hand boundary of the TextArea control and then continues on to the next line?? The TextArea considers that all as one line, so I can’t just use something like Me.LineNumAtCharPos(Len(me.Text)) in the KeyDown event of the TextArea control.

Since I got no responses to my earlier question about creating bulleted text and indents, I figured there was no easy way of doing it … so, this is my first (of probably many) questions I’ll ask in an effort to create something of my own to do what I need.

Could someone point me in the right direction here to get me started, please?

[quote=117166:@Don Lyttle]How can I detect when a line of text reaches the right-hand boundary of the TextArea control and then continues on to the next line?? The TextArea considers that all as one line, so I can’t just use something like Me.LineNumAtCharPos(Len(me.Text)) in the KeyDown event of the TextArea control.

Since I got no responses to my earlier question about creating bulleted text and indents, I figured there was no easy way of doing it … so, this is my first (of probably many) questions I’ll ask in an effort to create something of my own to do what I need.

Could someone point me in the right direction here to get me started, please?[/quote]

There is no built in method in the TextArea to tell you when a line wrap occurs. You may use Graphics.StringWidth and graphics.StringHeight. Here is an example which monitors the width and height of the text inside of a TextArea. The moment when the wrap occurs, StringWidth changes, so you know it happened.

Sub TextChange() dim p as new picture(me.width,me.height) p.graphics.TextSize = me.textsize p.graphics.TextFont = me.textfont Label2.text = str(p.graphics.stringwidth(me.text))+" "+str(p.graphics.StringHeight(me.text, me.width)) End Sub

Thanks for your help, Michel. I know I’m probably going to say “DOH” when I see your answer, but where do I put that code you suggest? I created a Label2 control to display the result the way you have it set and tried the code inside the KeyDown, but it throws a “Platform Not Supported Exception” … BTW, this is a desktop app using Windows 7 (I was remiss in saying that up front).

Thanks in advance for your reply.
… Don

Either turn on gdi+ or use new picture (me.width, me.height, 32)

The code is to go into the TextChange event of the TextArea. You will notice that what I posted starts with

Sub TextChange() which indicates the name of the event, and it ends with End sub. These two lines you do not want to copy.

Tim gave you the solution to avoid the error.

Here is the corrected code :

dim p as new picture(me.width,me.height,8) p.graphics.TextSize = me.textsize p.graphics.TextFont = me.textfont Label2.text = str(p.graphics.stringwidth(me.text))+" "+str(p.graphics.StringHeight(me.text, me.width))

What you then do is place code that monitors p.graphics.StringHeight. When it jumps, you got a new line.

Fantastic! Thanks so much for your patience, Michel, and your input, Tim. You guys’ help is sincerely appreciated!

BTW, Michel … referring to the routine as “TextChange()” as you did was rather self-explanatory, wasn’t it. There’s the “DOH” I promised … I saw it with my own eyes and still it just didn’t register. Thanks for the “wakeup call” ^^ … think it’s time to give up the ghost for the day and plow back in tomorrow morning.