Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

RichTextBox and wordwrap

6 views
Skip to first unread message

Pete Sackett

unread,
Dec 5, 2002, 11:27:14 AM12/5/02
to
Is there any way to turn off word wrapping in the RichTextBox control?

TIA
Pete


dnagel

unread,
Dec 5, 2002, 11:32:49 AM12/5/02
to
I believe theres a margin property...

Set it to something WAY high...

D.

"Pete Sackett" <psac...@nospam.fuse.net> wrote in message
news:u3ZSlsHnCHA.2224@TK2MSFTNGP11...

Rick Rothstein

unread,
Dec 5, 2002, 11:55:40 AM12/5/02
to
"Pete Sackett" <psac...@nospam.fuse.net> wrote in message
news:u3ZSlsHnCHA.2224@TK2MSFTNGP11...
> Is there any way to turn off word wrapping in the RichTextBox control?

Set the RichTextBox1.RightMargin = n <<n in Twips>>

where the "n" means pick some number that will be larger than the number
of Twips for the longest amount of text you expect on a single line. For
example, try setting the RightMargin to 30000 to get an idea of how this
will work. Note that word wrapping will occur when the width of the text
exceeds the RightMargin.

Rick - MVP

Gordon Bell

unread,
Dec 5, 2002, 12:54:38 PM12/5/02
to

Hi Pete,

You can mess with the margins as suggested, or use this simple API call:

Add the following to a Module:

Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA"
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal LParam
As Long) As Long

Public Const WM_USER = &H400
Public Const EM_SETTARGETDEVICE = (WM_USER + 72)

Public Sub SetWordWrap(ByRef pctl As Control, ByVal pbWordWrap As Boolean)
If pbWordWrap Then
SendMessageLong pctl.hWnd, EM_SETTARGETDEVICE, 0, 0
Else
SendMessageLong pctl.hWnd, EM_SETTARGETDEVICE, 0, 1
End If
End Sub

Usage:

' Turn Word Wrap On
Call SetWordWrap(RichTextBox1, True)

' Turn Word Wrap Off
Call SetWordWrap(RichTextBox1, False)

Gordon Bell


"Pete Sackett" <psac...@nospam.fuse.net> wrote in message
news:u3ZSlsHnCHA.2224@TK2MSFTNGP11...

dnagel

unread,
Dec 5, 2002, 1:22:57 PM12/5/02
to
nice tip...

D.

"Gordon Bell" <gsb...@hotmail.com> wrote in message
news:u$2rtdInCHA.1612@TK2MSFTNGP10...

Pete Sackett

unread,
Dec 6, 2002, 12:35:53 AM12/6/02
to
Thanks, all, for your suggestions. Much appreciated.

Pete

"Pete Sackett" <psac...@nospam.fuse.net> wrote in message
news:u3ZSlsHnCHA.2224@TK2MSFTNGP11...

Pete Sackett

unread,
Dec 6, 2002, 12:43:50 AM12/6/02
to
Hello Gordon:

Thanks for the tip, it works well.

I am wondering how you discovered this solution - the MSDN library and MS
website contain no information on SendMessageLong, much less the constants /
values to be passed by it to accomplish the desired effect.

Thanks,
Pete

"Gordon Bell" <gsb...@hotmail.com> wrote in message
news:u$2rtdInCHA.1612@TK2MSFTNGP10...
>

0 new messages