Textbox question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Anyone know of a way to tell the .Net textbox control to not break on word
boundaries? I'm building a control that I need to break on character
boundaries instead.

Thanks,
Todd
 
Yeh, it breaks on word boundaries. I need this to wrap on single characters,
regardless of where spaces are. And it looks like this is something that's
built into the logic of the Texbox. The WordWrap property is also a member
of the TextboxBase class... the class that TextBox inherits from. So it
doesn't seem that the wordwrap logic can be overriden.

I'm checking into writing my own "editor" for this. I would like to be able
to specify a record (character) length, where one record fits on a line. But
if the user inserts or deletes character(s), the rest of the characters will
shift, moving to the next line or the previous line. There are a couple of
other things that I need to do different that I don't think are going to work
quite right if I try to ductape the texbox and the functionality together.

I can't find anything that talks about how to write a textbox from scratch.
You guys have any resources on this?
 
I haven't totally thought this through and I don't know all your reqirments,
however, have you considered overriding the KeyPress event. In this event,
measure the length of the string and add line break characters when the
string gets to the length of the textbox.

I don't know the exact syntax but I think it woud go something like this.

In your custom textbox control load
- Get a graphics object from the textbox.
- Calculate the size of a single character ('M')
- Determine how many characters can fit into the textbox based on the
textbox size.

In the override for KeyPress
- Insert line breaks every so many characters as determined in the load.

I say to calculate the size of 'M' in the constructor to provide better
performance, however, if you have a line of 'i's and a line of 'M''s the
line of 'i's will be much shorter. So you may need to do the size
calculation in the KeyPress. Loop through each character calcualting the
cumulative length. When the cumulative length exceeds the length of the
textbox insert a line break.

Let me know how this worked out. I am curious if there is a big performance
hit for recalculating the size on the KeyPress.

--
Tom Krueger

My Blog - http://weblogs.asp.net/tom_krueger
Smart Client DevCenter - http://msdn.microsoft.com/smartclient/
Mobile DevCenter - http://msdn.microsoft.com/mobility

This posting is provided "as is" with no warranties and confers no rights.
 
There are some other requirements involved:

1) There is a column counter at the top, so I need to be able to control
where everything is drawn
2) I eventually want the user to be able to configure their own columns
using the column counter kinda like importing a text file into SQL Server
3) Record (line) length should be configurable and each record will be
displayed on a single line
4) When user types the record length is enforced and "extra" characters flow
over to the next line one by one

There are also a few others, but with just these it would put me jumping
thru hoops to get it to work. I'd rather just have a cleanly written
control, even if it is from scratch. I've got it displaying correctly, just
need to get the scrolling in and figure out a way to display the column names
as a column may only be one character.
 
Here is an excerpt from a previous post when this same question came up ...

There are some other requirements involved:

1) There is a column counter at the top, so I need to be able to control
where everything is drawn
2) I eventually want the user to be able to configure their own columns
using the column counter kinda like importing a text file into SQL Server
3) Record (line) length should be configurable and each record will be
displayed on a single line
4) When user types the record length is enforced and "extra" characters flow
over to the next line one by one

There are also a few others, but with just these it would put me jumping
thru hoops to get it to work. I'd rather just have a cleanly written
control, even if it is from scratch.
 
Hi Todd,

It sounds like you want to create a grid control that has textboxes in the
cells where the textboxes wrap as the specified length. The textboxes
should wrap on a character basis opposed to a end of word basis.

Have you tried the solution I suggested? I don't see why it wouldn't work.
The additional requirements you provided, seems to lead to a grid control so
you will need to apply the concept of calculating length to a Data Grid
Column Style.

Maybe I could help more if you tell me why my suggestion would not work.
I'm not saying that it will, I'm just saying I don't see any reason it
wouldn't work at this time.

Take care,

Tom


This posting is provided "as is" with no warranties and confers no rights.
 
Thanks for the suggestion. What about selecting text between textboxes and
that sort of thing? The philosophy behind this was that it would be a true
editor where you can edit and save text. We have a formatted text file that
our applications use and when it gets out of whack it's very hard to edit it
and line the columns back up to see what's going on. That's why I had the
idea to create this control. Think I've got all the keyboard stuff done
except implementing text selection and the fact that all the characters typed
are uppercase, which isn't that big of a deal cause all of our text is
uppercase anyway. It just bothers me cause I can't seem to figure out why.

The control looks like the text import control that SQL Server uses. It has
the column counter at the top. I also had a thought that I would allow a
format specification to be created by allowing the user to drag the column
separators from column to column, again like the SQL Server text import
control. Again, thanks for the input. I welcome any ideas that I may not
have had. This is my first implementation of an editor from scratch. I'm
learning that there's a lot we take for granted when using controls and have
a new-found respect for the guys that have to write them.
 
Back
Top