Public const wm_user = & h400public const EM_SETTARGETDEVICE = (WM_USER 72)
Public Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As LongPublic 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 'provided RichTextBox wrap Call SendMessage (RichText.hWnd, EM_SETTARGETDEVICE, _ GetDC (RichText.hWnd), RichText.Width / 15) If RichText.RightMargin = 0 dam = 1 else richtext.rightmargin = 0 end if else 'Setting RichTextBox does not automatically wrap Call sendMessage (richtext.hwnd, em_settargetDevice, 0, 1) end ifend sub
Calling method: AutoSwitchline RichtextBox1, the code above the False makes RichTextBox1 not automatically wrap.
The above is a comparative formal method. If it is simple, the following two code can be:
RichtextBox1.multiline = trueerichtextbox1.rightmargin = 10000