
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/