Limitting line length of each line within multiline textbox 
Author Message
 Limitting line length of each line within multiline textbox

Does anyone know how to limit the input to say 2 lines of at most 22 chars
each in a multiline textbox....i've been fooling around with the
EM_LINELENGTH, but i'm missing something....

Craig Hamilton




Sat, 10 Oct 1998 03:00:00 GMT  
 Limitting line length of each line within multiline textbox

Quote:
>Does anyone know how to limit the input to say 2 lines of at most 22 chars
>each in a multiline textbox....i've been fooling around with the
>EM_LINELENGTH, but i'm missing something....

This is a workaround.

Add a text control named Text1 to a form. Then add this code:

[declarations]

Option Explicit

Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg
As Integer, ByVal wParam As Integer, lParam As Any) As Long
   Const WM_USER = &H400
   Const EM_GETLINECOUNT = WM_USER + 10
   Const EM_LINELENGTH = WM_USER + 17

Function LineCount% (txt As Control)
Dim x&, h%

   h% = txt.hWnd
   x& = SendMessage(h%, EM_GETLINECOUNT, 0, 0)
   LineCount% = x&

End Function

Function LineLength% (txt As Control)
Dim x&, h%

   h% = txt.hWnd
   x& = SendMessage(h%, EM_LINELENGTH, txt.SelStart, 0)

   LineLength% = x&

End Function

Sub Text1_KeyPress (KeyAscii As Integer)

   Select Case KeyAscii
      Case 13
         If LineCount(Text1) = 2 Then
            Beep
            KeyAscii = 0
         End If
      Case 8
      Case Else
         If LineLength(Text1) = 22 Then
            Beep
            KeyAscii = 0
         End If
   End Select

End Sub


--
Real programmers never work 9 to 5. If any Real Programmers are
around at 9:30 AM, it's because they were up all night.

http://www.sn.no/~balchen/
ftp://ftp.sn.no/user/balchen/



Sun, 11 Oct 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Read a MultiLine textbox line by line?

2. Newbie: creating a fixed-line-length file from a variable-line-length file

3. Line length & count for multiline Text Box

4. Multiline Textbox Cause Page Overflows when Printing or doesn't print all lines

5. finding line number cursor is in multiline textbox

6. forcing multiline textbox to scroll to last line...

7. Finding Line number in MultiLine TextBox (VB4)

8. Reading a single line in a multiline textbox

9. HELP:limiting # of lines in a Multiline Textbox

10. Line limit in Multiline Textbox

11. Retrieving text lines in multiline textbox

12. Multiline Textboxes - Limiting Characters Per Line

 

 
Powered by phpBB® Forum Software