I have to limit the number of lines and characters per line in an UltraFormattedTextEditor. For example: maximum 4 lines and maximum 20 characters per line.
The number of lines is not that difficult, I'm counting the number of crlf's in the keypress event.
But I also want a maximum number of characters per line. I'm having difficulty with this one because I don't know where the user is typing. How can this be done? It's no big deal in itself to check how many characters there are on a line but I would like to prevent the user from entering the character if he tends to exceed the maximum on the line he is typing.
I ended up with creating creating an extra class to handle all this. Based on the keydown event. I added the class as a zip.
Here is the code how I use it (you have to add the handlers to your textbox but you can figure this out):
Public Sub Handle_KeyDownHeader(sender As Object, e As System.Windows.Forms.KeyEventArgs)
If (e.KeyCode = Keys.Delete Or e.KeyCode = Keys.Back Or e.KeyCode = Keys.Home Or e.KeyCode = Keys.End _
Or e.KeyCode = Keys.Left Or e.KeyCode = Keys.Right Or e.KeyCode = Keys.Up Or e.KeyCode = Keys.Down) Then
Exit Sub
End If
Dim lines As Integer = TotalLines(Nothing)
If (lines >= _maxlines) Then
e.SuppressKeyPress = True
e.Handled = True
End Sub
Public Sub Handle_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs)
Dim txt As UltraFormattedTextEditor = sender
Dim lines As Integer = TotalLines(txt)
_limit.MAX_LINES = _maxlines - lines
_limit.Handle_KeyDown(txt, e)
Private Function TotalLines(ExcludedTxt As UltraFormattedTextEditor) As Integer
Dim total As Integer = 0
For Each txt As UltraFormattedTextEditor In _colTxt
If (txt IsNot ExcludedTxt) Then
total += _limit.NumberOfLines(txt.Text)
Next
For Each txt As UltraTextEditor In _colHdr
If (Not String.IsNullOrEmpty(txt.Text)) Then _
total += 1
Return total
End Function
Private Function TotalLines() As Integer
No, this feature has no been implemented at this time.
Has there been a release with this feature? I'm looking for it as well. Thanks!
I did a bit of experimenting myself and figured it out:
With this combination it is possible because using the cursor position and counting the number of CRLF's you can determine the line the cursor is in so then you also know if the next typed character is too much for this line or not.
The approximate behavior that you have described may be acheived with the ultraTextEditor and one such work-around could include applying its WordWrap property and modifying the available area within the editor to accommodate only the desired amount of lines and characters to be displayed; then implementing a conditional statement triggered by the KeyPress or similar event to limit the number of characters for the control.
Within the conditional statement, I would set the maximum number of allowed characters for the control and treat those characters as a single string. Once the maximum character threshold has been reached, limit the input; for example perhaps by triggering the backspace key every time a character over this limit has been entered, as there is no way to explicitly cancel the KeyPress event.
I have constructed and attached sample which demonstrates this simple approach as one alternative, in the meantime of the feature request possibly being implemented in the future.
If this feature is urgently required, I would highly recommend contacting our consulting team which will work closely with you to develop custom functionality like the one described in your inquiry. I have included a link to our consulting services page below, for reference.
http://ko.infragistics.com/services/ui/default.aspx#UIUserInterfaceServices
If I may be of any further assistance regarding this issue, please let me know.
Sincerely,Chris KDeveloper Support EngineerInfragistics, Inc.www.infragistics.com/support