Public const wm_user = & H400
Public const em_settargetdevice = (wm_user + 72)
Public declare function getdc lib "USER32" (byval hwnd as long) as long
Public declare function sendmessage lib "USER32" alias "sendmessagea "_
(Byval hwnd as long ,_
Byval wmsg as long ,_
Byval wparam as long ,_
Lparam as any) as long
Public sub autoswitchline (byref richtext as RichTextBox, byval bswitch as Boolean)
If bswitch then
'Set RichTextBox to wrap automatically
Call sendmessage (richtext. hwnd, em_settargetdevice ,_
Getdc (richtext. hwnd), richtext. width/15)
If richtext. rightmargin = 0 then
Richtext. rightmargin = 1
Else
Richtext. rightmargin = 0
End if
Else
'Set RichTextBox not to wrap automatically
Call sendmessage (richtext. hwnd, em_settargetdevice, 0, 1)
End if
End sub
Call method:
Autoswitchline richtextbox1, false
The above Code makes richtextbox1 not automatically wrap.
The above is a more formal method. If it is simple, the following two sentences of code can be used:
Richtextbox1.multiline = true
Richtextbox1.rightmargin = 10000