Read-only multi-line textbox
By: Unknown Date: 13/07/1998

This article describes how to make a multi-line textbox read-only without graying out the text or losing the use of the scroll bars.

First of all, declare the necessary constants, Sub, and Function as indicated below.

Public Const WM_USER = &H400
Public Const EM_SETREADONLY = (WM_USER + 31)

Declare Function HideCaret Lib "user32" Alias "HideCaret" (ByVal hwnd As Long) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Then, create a Sub like the following one:

Sub MakeReadOnly (TextBoxhWnd%)
    Dim x As Integer

    x = SendMessage(TextBoxhWnd%, EM_SETREADONLY, 1, 0)
    HideCaret TextBoxhWnd%

End Sub

Finally, call the Sub passing the hWnd (Windows handle) of the textbox as the only argument as in the example below:

MakeReadOnly (textbox.hWnd)
where textbox is the name of the multi-line textbox to disable.

Click Here!


Visual Basic Programming Zone is a website by Lorenzo Dalla Vecchia.
Webmaster's e-mail: webmaster@vbprogzone.cjb.net
Hosted by InWind: www.inwind.it