Prev: API-Guide
Next: Find Addin
From: Bee on 4 Apr 2010 10:29 I I use plain text, then there is no problem. But if I use richtext, it is then that the word wrap is beyond the right edge of the control. The richtrxt contains bold, underline, tabs, ad a single but larger font size. I have tried different fonts but that does not change anything. I have modified my algo a little to use the SQR() to give aqn exponention factor and this seems to keep the right wrpa approximately the same as the RTB is sized. Otherwise the right wrap moves fartyre to the left proportionally as the box is expanded. "Bee" wrote: > I have tried these two methods and neither one works. > Both still leave text past the vertical scrollbar. No horz scrollbar. > > (A) > Public Sub RTBWordWrap(RTB As RichTextBox, Optional bSet As Boolean = True) > > If bSet Then > ' then to set word wrap, use this : > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 0 > Else > ' and to do the oposite use this one : > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 1 > End If > > End Sub 'RTBWordWrap > > (B) in _Resize > RichTextBox.RightMargin = RichTextBox.Width > If I do > RichTextBox.RightMargin = RichTextBox.Width * .75 > this woks better for wide RTB but when the RTB gets narrow, words again go > past the vert scrollbar. > > Does this have to do with thiings like Bold etc that may not be accounted > for correctly? > > I am using rich text not plain text. >
From: Helmut Meukel on 4 Apr 2010 12:46 Bee, there is something weird in your app. Try a new test app, simple put a RTB there, don't set _any_ properies for the RTB. Save any Word document you have (say a letter) as rtf and load _this_ rtf file into the RTB. I bet it will display ok! Then test it with your special rtf files. If they display ok, it's one of the settings in your app. Helmut. "Bee" <Bee(a)discussions.microsoft.com> schrieb im Newsbeitrag news:DB5E2736-2DA9-48F0-805A-BC8E116C9707(a)microsoft.com... >I I use plain text, then there is no problem. > But if I use richtext, it is then that the word wrap is beyond the right > edge of the control. The richtrxt contains bold, underline, tabs, ad a > single but larger font size. I have tried different fonts but that does not > change anything. > I have modified my algo a little to use the SQR() to give aqn exponention > factor and this seems to keep the right wrpa approximately the same as the > RTB is sized. > Otherwise the right wrap moves fartyre to the left proportionally as the box > is expanded. > > > > "Bee" wrote: > >> I have tried these two methods and neither one works. >> Both still leave text past the vertical scrollbar. No horz scrollbar. >> >> (A) >> Public Sub RTBWordWrap(RTB As RichTextBox, Optional bSet As Boolean = True) >> >> If bSet Then >> ' then to set word wrap, use this : >> SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 0 >> Else >> ' and to do the oposite use this one : >> SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 1 >> End If >> >> End Sub 'RTBWordWrap >> >> (B) in _Resize >> RichTextBox.RightMargin = RichTextBox.Width >> If I do >> RichTextBox.RightMargin = RichTextBox.Width * .75 >> this woks better for wide RTB but when the RTB gets narrow, words again go >> past the vert scrollbar. >> >> Does this have to do with thiings like Bold etc that may not be accounted >> for correctly? >> >> I am using rich text not plain text. >>
From: Mike Williams on 4 Apr 2010 17:03 "Bee" <Bee(a)discussions.microsoft.com> wrote in message news:D748AC50-305E-41D7-8DF6-C01F8D98BCCF(a)microsoft.com... > I cannot get my RTB to wrap properly. I have tried these > two methods and neither one works. Both still leave text > past the vertical scrollbar. The text does wrap but not at the > end of the actual proper point. As I resize, the text wrap > changes but still leaves several words off the right side. > [some stuff snipped] > RichTextBox.RightMargin = RichTextBox.Width > the following woks better for wide RTB but when the > RTB gets narrow, words again go past the vert scrollbar. > RichTextBox.RightMargin = RichTextBox.Width * .75 If you just want the contents to wrap properly regardless of the current Width of the RTB, whatever you to its size it to, then setting its Multiline property to True and its RightMargin property to zero at design time (or in code) should do the trick. You should not need to keep doing it every time you resize. If that is not what is happening at your end then perhaps you are using and old version of the RichTextBox control? The RTB that shipped with VB5 had problems with a zero RightMargin setting, causing it to fail to wrap unless you set the RightMargin to a positive value. Is that why you are repeatedly setting the RightMargin each time you resize it? Are you using an old RTB in VB5? If you are using VB5 then have you checked whether there is an updated RTB that you can download for it that does not have the zero RightMargin problem? Otherwise, if you are stuck with setting its RightMargin to a real positive value in order to overcome the bug then you need to set it to the correct value (this would also apply if for some reason you were setting the RightMargin to a real positive value in the VB6 RTB). In your code samples you are setting the RightMargin to the Width of the RTB, which of course is its overall width, including its borders and the vertical scroll bar (if you are displaying one). That's probably why some of the text is going past the right edge of its available client area, which is of course narrower than its overall width. To get the correct value you need to check its client width. You can get this using the GetClientRect API, which will return a RECT containing the size of the RTB's client area. Then subtract a couple of pixels from that value (because the RTB by default has at least a one pixel left margin) and use that calculated value to set the RTB's RightMargin property. You'll need to convert the calculated pixel value into the scale units of the RTB's container (your Form or whatever) because the RightMargin property of the RTB is the distance in container scale units from the left edge of the RTB, and NOT the distance in twips from the right edge of the RTB as stated in the VB6 help files!). Mike > > (A) > Public Sub RTBWordWrap(RTB As RichTextBox, Optional bSet As Boolean = > True) > > If bSet Then > ' then to set word wrap, use this : > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 0 > Else > ' and to do the oposite use this one : > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 1 > End If > > End Sub 'RTBWordWrap > > (B) in _Resize > RichTextBox.RightMargin = RichTextBox.Width > If I do > RichTextBox.RightMargin = RichTextBox.Width * .75 > this woks better for wide RTB but when the RTB gets narrow, words again go > past the vert scrollbar. > > Does this have to do with thiings like Bold etc that may not be accounted > for correctly? > > I am using rich text not plain text. >
From: Bee on 4 Apr 2010 22:10 This first thing I did was to check the version. About shows it as V6 SP6. I copied a RTB from a different part of the app (on a different form) over this the misbehaving form. Hoping that some parameter would be the problem. The copied RTB was using plain text set to Lucida Consols and it was wrapping correctly. After the copy and rename, the copied form FAILED! just like the one taht replaced it. I searched the code source for any RTB settings and found nothing. I made sure I set the Multiline and RightMargin=0 as was before. The wrap occurs several words past the right vertical scroll bar not just into the vert scroll bar. The wrap changes location relative to the width the RTB is resized. i.e. narrow has less distance to the right side and wide has a lot of distance. It must have something to do with the rich text that theRTB is trying to display. This rich text was edited in a number of editors but always saves as .rtf but ??? I used WordPad, Word 2003 and OpenOffice Writer (latest). I am wondering if some hidden control characters are fooling the wrap algo. I will try loading some plain text and see. I will take the rich text and run it through Notepad to remove all the hidden stuff. (load in Wordpad, select all, copy, paste into Notepad). "Mike Williams" wrote: > "Bee" <Bee(a)discussions.microsoft.com> wrote in message > news:D748AC50-305E-41D7-8DF6-C01F8D98BCCF(a)microsoft.com... > > > I cannot get my RTB to wrap properly. I have tried these > > two methods and neither one works. Both still leave text > > past the vertical scrollbar. The text does wrap but not at the > > end of the actual proper point. As I resize, the text wrap > > changes but still leaves several words off the right side. > > [some stuff snipped] > > RichTextBox.RightMargin = RichTextBox.Width > > the following woks better for wide RTB but when the > > RTB gets narrow, words again go past the vert scrollbar. > > RichTextBox.RightMargin = RichTextBox.Width * .75 > > If you just want the contents to wrap properly regardless of the current > Width of the RTB, whatever you to its size it to, then setting its Multiline > property to True and its RightMargin property to zero at design time (or in > code) should do the trick. You should not need to keep doing it every time > you resize. If that is not what is happening at your end then perhaps you > are using and old version of the RichTextBox control? The RTB that shipped > with VB5 had problems with a zero RightMargin setting, causing it to fail to > wrap unless you set the RightMargin to a positive value. Is that why you are > repeatedly setting the RightMargin each time you resize it? Are you using > an old RTB in VB5? > > If you are using VB5 then have you checked whether there is an updated RTB > that you can download for it that does not have the zero RightMargin > problem? Otherwise, if you are stuck with setting its RightMargin to a real > positive value in order to overcome the bug then you need to set it to the > correct value (this would also apply if for some reason you were setting the > RightMargin to a real positive value in the VB6 RTB). > > In your code samples you are setting the RightMargin to the Width of the > RTB, which of course is its overall width, including its borders and the > vertical scroll bar (if you are displaying one). That's probably why some of > the text is going past the right edge of its available client area, which is > of course narrower than its overall width. To get the correct value you need > to check its client width. You can get this using the GetClientRect API, > which will return a RECT containing the size of the RTB's client area. Then > subtract a couple of pixels from that value (because the RTB by default has > at least a one pixel left margin) and use that calculated value to set the > RTB's RightMargin property. You'll need to convert the calculated pixel > value into the scale units of the RTB's container (your Form or whatever) > because the RightMargin property of the RTB is the distance in container > scale units from the left edge of the RTB, and NOT the distance in twips > from the right edge of the RTB as stated in the VB6 help files!). > > Mike > > > > > > > > > > > > > > (A) > > Public Sub RTBWordWrap(RTB As RichTextBox, Optional bSet As Boolean = > > True) > > > > If bSet Then > > ' then to set word wrap, use this : > > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 0 > > Else > > ' and to do the oposite use this one : > > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 1 > > End If > > > > End Sub 'RTBWordWrap > > > > (B) in _Resize > > RichTextBox.RightMargin = RichTextBox.Width > > If I do > > RichTextBox.RightMargin = RichTextBox.Width * .75 > > this woks better for wide RTB but when the RTB gets narrow, words again go > > past the vert scrollbar. > > > > Does this have to do with thiings like Bold etc that may not be accounted > > for correctly? > > > > I am using rich text not plain text. > > > > . >
From: Bee on 4 Apr 2010 22:26
OK. Still not sure what the real problem is however ... if I use the pure text (taken directly from the richtext) as outlined above and load it into the RTB as always, renamed .rtf (though really a .txt file) it works as follows: (1) using .RightMargin = .Width the wrap occurs in the vert scrollbar but only by a few characters (not many word). Still not very nice. (2) using the sendmessage of RTBWordWrap() the wrap occurs well inside (really nice) the vert scrollbar. But of course this is not the richtext I want! Looks like the hidden formatting stuff is influencing the wrap position incorrectly. Of course M$ will fix that in the next realease of VB6. lol. (really crying). Now looking ofr the best workaround. Is there such a thing as a richtext cleaner? "Mike Williams" wrote: > "Bee" <Bee(a)discussions.microsoft.com> wrote in message > news:D748AC50-305E-41D7-8DF6-C01F8D98BCCF(a)microsoft.com... > > > I cannot get my RTB to wrap properly. I have tried these > > two methods and neither one works. Both still leave text > > past the vertical scrollbar. The text does wrap but not at the > > end of the actual proper point. As I resize, the text wrap > > changes but still leaves several words off the right side. > > [some stuff snipped] > > RichTextBox.RightMargin = RichTextBox.Width > > the following woks better for wide RTB but when the > > RTB gets narrow, words again go past the vert scrollbar. > > RichTextBox.RightMargin = RichTextBox.Width * .75 > > If you just want the contents to wrap properly regardless of the current > Width of the RTB, whatever you to its size it to, then setting its Multiline > property to True and its RightMargin property to zero at design time (or in > code) should do the trick. You should not need to keep doing it every time > you resize. If that is not what is happening at your end then perhaps you > are using and old version of the RichTextBox control? The RTB that shipped > with VB5 had problems with a zero RightMargin setting, causing it to fail to > wrap unless you set the RightMargin to a positive value. Is that why you are > repeatedly setting the RightMargin each time you resize it? Are you using > an old RTB in VB5? > > If you are using VB5 then have you checked whether there is an updated RTB > that you can download for it that does not have the zero RightMargin > problem? Otherwise, if you are stuck with setting its RightMargin to a real > positive value in order to overcome the bug then you need to set it to the > correct value (this would also apply if for some reason you were setting the > RightMargin to a real positive value in the VB6 RTB). > > In your code samples you are setting the RightMargin to the Width of the > RTB, which of course is its overall width, including its borders and the > vertical scroll bar (if you are displaying one). That's probably why some of > the text is going past the right edge of its available client area, which is > of course narrower than its overall width. To get the correct value you need > to check its client width. You can get this using the GetClientRect API, > which will return a RECT containing the size of the RTB's client area. Then > subtract a couple of pixels from that value (because the RTB by default has > at least a one pixel left margin) and use that calculated value to set the > RTB's RightMargin property. You'll need to convert the calculated pixel > value into the scale units of the RTB's container (your Form or whatever) > because the RightMargin property of the RTB is the distance in container > scale units from the left edge of the RTB, and NOT the distance in twips > from the right edge of the RTB as stated in the VB6 help files!). > > Mike > > > > > > > > > > > > > > (A) > > Public Sub RTBWordWrap(RTB As RichTextBox, Optional bSet As Boolean = > > True) > > > > If bSet Then > > ' then to set word wrap, use this : > > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 0 > > Else > > ' and to do the oposite use this one : > > SendMessageLong RTB.hwnd, EM_SETTARGETDEVICE, 0, 1 > > End If > > > > End Sub 'RTBWordWrap > > > > (B) in _Resize > > RichTextBox.RightMargin = RichTextBox.Width > > If I do > > RichTextBox.RightMargin = RichTextBox.Width * .75 > > this woks better for wide RTB but when the RTB gets narrow, words again go > > past the vert scrollbar. > > > > Does this have to do with thiings like Bold etc that may not be accounted > > for correctly? > > > > I am using rich text not plain text. > > > > . > |