Setting and cancel automatic wrap in RichTextBox

xiaoxiao2021-03-05  20

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

转载请注明原文地址:https://www.9cbs.com/read-37957.html

New Post(0)